visit
Parameters
The parameters section allows you to create parameters (duh). Using parameters allows you to create a single template that can be reused across multiple environments. Just change the parameter values and you have a new environment--or at least an updated one.Note: you are , but if you need that many you're probably doing something wrong!To define a parameter, you only need to specify an ID and type. You can find the full list of parameter settings in the . The following example shows how to define a string parameter named InputBucketName in YAML.
Parameters:
InputBucketName:
Type: String
Resources
Resources are the real reason you're creating this template in the first place. They define everything that you actually want to create in AWS. Similar to the parameters, each resource requires an ID and a Type.The IDs defined in CloudFormation are only used within the template. When the template is deployed the IDs may or may not be used as the resource name. BTW: the IDs are referred to as a Logical ID.
The type names follow the pattern
AWS::<service>::<resource_type>
. So to create an S3 bucket you want to create a resource of type AWS::S3::Bucket
.Resources:
BigBucket:
Type: AWS::S3::Bucket
If you want to override those default values, you need to provide them in the resource's
Properties
. For example, if you want to set the bucket's name, use the aptly named BucketName
property.Resources:
BigBucket:
Type: AWS::S3::Bucket
Properties:
BucketName:
Ref: InputBucketName
Outputs
Now that the bucket is created, how do you use it? You could figure out the bucket's URL from the name parameter, but what if you want to create an IAM role that references it in another stack?That's exactly what outputs are for. You define values that will be needed by another stack as an output, then you can import that value when creating the other stack.To output the URL for our bucket, create an output section that looks like this:Outputs:
BigBucketUrl:
Value:
Fn::GetAtt: ["BigBucket", "WebsiteURL"]
Save all of the above sections into the file
cf.yml
and run the following command:aws cloudformation deploy --template-file ./cf.yaml --stack-name cf-101-tutorial --parameter-overrides InputBucketName=$USER
aws cloudformation delete-stack --stack-name cf-101-tutorial
Previously published at