Demo - Simple Non-Portable Template
Non-Portable templates are not recommended.
- Navigate to the AWS console in the N. Virginia Region
- Create a key pair in the EC2 console and call it BYKeyPair and save the pem file.
- Move to the CloudFormation console.
- Open up your favorite code editor.
- Don't copy this entire code block at once. Type each line in one line at a time, watching for spacing and set up your code editor to handle the spacing as needed. You may need to substitute in the AMI from the EC2 console.
Resources:
Bucket:
Type: "AWS::S3::Bucket"
Properties:
BucketName: "babyyodas3bucket242424"
Instance:
Type: "AWS::EC2::Instance"
Properties:
KeyName: "BabyYodaKeyPair"
InstanceType: "t2.micro"
ImageId: "ami-0c02fb55956c7d316"
- Save this as
nonportable.yaml
Deploy this Template
-
Navigate back to the CloudFormation console and click
Create Stack
-
Upload this stack
-
Click Next, Next, Create Stack
-
This should create 2 resources when it moves into the Create Complete state.
-
Now, create a new stack and then upload this same file again and it will fail.
-
Look under events to see why it failed. You'll notice that it failed because the bucket already exists. Looking at your template, it has the name hardcoded in and if you try to run it more than once, it fails. The best solution is to create a way to add some random characters to the end of this so that you can run it 100 times and it works every (almost) every time. Non-portable templates are not recommended. I'll repeat that again.
-
Delete both of these stacks to delete the resources
-
Click another region and create another stack and upload the file and click Create Stack. The bucket name doesn't exist this time, so it should create. No. It doesn't. Why?
-
AMI is specific to regions. You're using the us-east-1 AMI in another region.
-
Delete this stack to clean up.