Lab complete!
Now that you have completed this lab, make sure to update your Well-Architected review if you have implemented these changes in your workload.
Click here to access the Well-Architected Tool
In this task, you will gain experience in editing a CloudFormation template and updating your CloudFormation stack
simple_stack.yaml
file you downloaded earlier to include an Amazon S3 bucketOnce you have edited the template, continue with the following steps to update the stack.
simple_stack.yaml
, your edited CloudFormation template filesimple_stack.yaml
fileIf you did not see an error you may proceed
cloudformationlab-mys3bucket-<some_random_string>
.The name for the S3 bucket was auto-generated by CloudFormation based on your CloudFormation stack name (converted to lowercase), plus the string “mys3bucket”, plus a randomly generated string.
For this task you are going to specify a Parameter where you can set the bucket name. To do this you will add a property on the S3 bucket resource that uses this parameter.
Under the Parameters section of your simple_stack.yaml
template look at the S3BucketName parameter
It is not currently used in the template
# S3 Bucket
S3BucketName:
Type: String
Description: The name for the S3 bucket - must be unique across all of AWS (3-63 lowercase letters or numbers)
Default: replaceme
AllowedPattern: '^[a-z0-9]{5,40}$'
ConstraintDescription: 3-63 characters; must contain only lowercase letters or numbers
It is a string for which we have configured certain constraints
The AllowedPattern is a regular expression specifying only lowercase letters or numbers and a string length between 3-63 characters
This satisfies the constraints on what is allowed in an S3 bucket name
It is actually more constrictive than what is allowed. See Rules for Bucket Naming under Bucket Restrictions and Limitations for more details.
Add a few more lines to your S3 bucket under in the Resources section of your template so it looks like this
Be cautious to maintain the two-space indents where indicated
MyS3Bucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Join
- '-'
- - !Ref S3BucketName
- !Ref 'AWS::Region'
The Properties label defines that the items that follow (indented underneath) are properties of the S3 bucket
For the BucketName property you are specifying a reference to another value in the template. Specifically you are indicating that the string entered as the S3BucketName parameter should be used as the name of the bucket
The !Join function concatenates strings in a CloudFormation template. Use that to add the AWS Region to make the bucket more unique. AWS::Region is a pseudo-parameter available within CloudFormation.
Save the file
Go to the AWS CloudFormation console
Click on Stacks
Click on the CloudFormationLab stack
Click Update
Now click Replace current template selected. This is different from what you did for the last update.
Click Upload a template file
Click Choose file
simple_stack.yaml
, your edited CloudFormation template fileClick Next – Look for any errors reported
On the Specify stack details look at the Parameters
Click Next again, until you arrive at the Review CloudFormationLab screen
It takes about a minute for the stack update to finish and the stack status is UPDATE_COMPLETE
Troubleshooting
<your_chosen_bucket_name> already exists
then re-do the CloudFormation update steps, but specify a more unique bucket nameNow that you have completed this lab, make sure to update your Well-Architected review if you have implemented these changes in your workload.
Click here to access the Well-Architected Tool