I noticed the aws console has "Create Template from Instance" option. Is there a boto3 or aws cli equivalent?
I want to create a launch template using python + boto3 from a given instance-id. However I don't want to go through all the minute details used to create the instance.
I've found the documentation for create_launch_template but did not see anything similar to this option.
I could not find any cli or boto3 api equivalent to "create template from instance" console option.
Related
We are in the way to migrate from api calls to terraform to spin resources/accesses/policies in aws. I was bit struct in a place where I could not find an option to pass CallerReference to aws terraform resource aws_cloudfront_origin_access_identity.
We have this option using api: https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CreateCloudFrontOriginAccessIdentity.html
Do we have any custom options for passing the same in other ways?
If its not directly supported by TF, you can always use local-exec with AWS CLI to create your origin identity.
I want to extend commands for aws-cli it is possible, I mean aws-cli has some library to extend some functionality, it hasn't? For example, I want to obtain the size in MB of my files in the bucketmio, May I could create some extension for that, e.g
aws s3 bucketmio get-size-all-files
get-size-all-files is the new extension that I want.
Thanks.
Yes, you can Create and use AWS CLI aliases, which are "shortcuts you can create in the AWS Command Line Interface (AWS CLI) to shorten commands or scripts that you frequently use. You create aliases in the alias file located in your configuration folder."
Here is an example that sends a message via Amazon SNS:
textalert =
!f() {
aws sns publish --message "${1}" --phone-number ${2}
}; f
You can write shell script that calls the AWS CLI but also adds additional logic around those calls.
I have a collection of CloudFormation templates that I'm using to create new resources but I also have a small percentage of AWS resources that were created outside of CF that I now want to import into CF. I know how to import existing resources into CF via the AWS dashboard but I want to do it with the CLI instead.
This is the documentation I thought would help but it appears to be out of date as I don't have a "--resources-to-import" option when I run aws cloudformation create-stack help. An up-to-date example would be very helpful if this is even possible via the command-line.
In step 4 of the CLI documentation on that page, it is actually a create-change-set call instead of a create-stack call:
aws cloudformation create-change-set --change-set-type IMPORT --resources-to-import
Is there any way to use a simple JSON file (of my instance details) to configure a Cloud Formation template?
That's basically what a CloudFormation template provides you. Since it is a template, you can also pass in parameters as variables.
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
Details on passing parameters from a config file:
https://aws.amazon.com/blogs/devops/passing-parameters-to-cloudformation-stacks-with-the-aws-cli-and-powershell/
You can have CFT parameters populated however you like. If you want to run / load the CFT from AWS console - add the parameters as either default or options within the CFT and choose them while creating the stack.
If you want to load them from a properties file - you can use any programming language of your choice to do so. A bash script that loads the properties or whatever, it's upto you and your use case. If you are using AWS cli to run the CFT use bash shell or power shell, if you are using AWS SDK to run your CFT - use the same language as your SDK etc.
If you are using just aws cli, you can do something like this with a json parameters file:
aws cloudformation create-stack --stackname startmyinstance
--template-body file:///some/local/path/templates/startmyinstance.json
--parameters file:///some/local/path/params/startmyinstance-parameters.json
I want to automatically roll out new versions of my Service Catalog product using a Lambda that runs weekly. I can't find a corresponding Boto3/AWS CLI command to do this, however. I see there is 'update_product', but there doesn't appear to be a way to use this command specify a version number,nor do I think there is a way to remove deprecated versions without removing the product itself with 'delete_product'.
Is there a way to do this versioning from the CLI?
Find the Product ID of the product you wish to update by using the command below, and note the value of the field named ProductId
aws servicecatalog search-products-as-admin
Upload the CloudFormation template to S3 and copy the URL to the template
Run the following command, inserting the Version Name, Product ID and the URL for the template in S3
aws servicecatalog create-provisioning-artifact --product-id INSERT_PRODUCT_ID --parameters Name=INSERT_VERSION_NAME,Info={LoadTemplateFromURL=INSERT_TEMPLATE_URL},Type=CLOUD_FORMATION_TEMPLATE
Use aws servicecatalog generate provisioning-artifact.
Hope these AWS S3 url's for AWS CLI options are of some help to you:
http://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-versioning.html
http://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-lifecycle-configuration.html