AWS Cloud Formation templates - amazon-web-services

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

Related

Requires capabilities : [CAPABILITY_IAM] Cloudformation AWS Console

I am getting Requires capabilities : [CAPABILITY_IAM] error when creating a stack on cloudformation.
Now I know we need to execute the command to create the stack with following parameter --capabilities CAPABILITY_IAM when using AWS CLI.
Question is how do I change the setting or solve this issue when using cloudformation from aws console so that I am able to create the stack by uploading the script using web console.
In the review pages you have option to allow that:

Confusing parameter for cloudFormation script

Hello i am planning to run the cloudFormation stack that is preconfigured by aws here.
It prompts me to fill out
NeptuneBulkloadIAMRoleArn
NeptuneClusterEndpoint
NeptuneLambdaIAMRoleArn
But i don't know what to fill in there, can you help me out?
The parameters you described above are used for the following:
NeptuneBulkloadIAMRoleArn - This is an IAM role setup to run the loader command. Instructions for setting this up found here.
NeptuneClusterEndpoint - This is the endpoint of your Neptune database, it will be accessible either from the console or the CLI.
NeptuneLambdaIAMRoleArn - This allows you to pass in your own role the Lambda should use, if not specified the CloudFormation stack should make one for you.

Use existing DBUser and DBPassword parameter values when updating stack

Does anyone know, if there's an option to use some kind of 'existingDBUser' and 'existingDBPassword parameter while describing DBUser and DBPassword in a Cloudformation template?
I don't want to use 'Default' params and when deploying template via cli it asks me for DBUser and DBPassword.
In my case if I specify that and it's different than ones assigned already to DBCluster it creates a new cluster instead of updating existing one.
There's a way to upload the template via AWS Console, where you can check the 'use existing' boxes.
How can I do that from CLI perspective?
Thanks for replies.
Yes, this is possible. You don't define this in the template, you specify this when you call the update stack command from the SDK or CLI.
You need to specify the "UsePreviousValue" attribute of the parameter when calling the UpdateStack.
Here is an example of how you would do it on the AWS CLI but the SDKs should also provide a similar functionality:
aws cloudformation update-stack \
--stack-name mystack \
--template-url https://s3.amazonaws.com/sample/updated.template \
--parameters ParameterKey=DBUser,UsePreviousValue=true \
ParameterKey=DBPassword,UsePreviousValue=true

Use AWS CLI to import existing resources into CloudFormation

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

Combine AWS CLI and CloudFormation?

I'm creating a new user pool in AWS Cognito. As you might know, CF support is missing for a lot of the features in Cognito, so I´ve resorted to using the CLI for Cognito. But I still want to use CloudFormation for other resources like API Gateway that will need to reference the new user pool.
Is there any way I can create parameters with the CLI that I can use in CloudFormation?
Yes, if you have Parameters in your template, then you can use the CloudFormation Deploy command to do exactly this.
For example, you can call aws cloudformation deploy --template-file <file_path> --stack-name <stack_name> --parameter-overrides ParameterKey1=ParameterValue1 ParameterKey2=ParameterValue2 ... where <file_path> is the path to your CloudFormation Template, and <stack_name> is the name of your CloudFormation Stack. If this stack doesn't exist yet, Deploy will create it, but if it does exist, Deploy will update it.