This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:widdix/learn-cloudformation
- Loading branch information
Showing
48 changed files
with
1,014 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
# learn-cloudformation | ||
|
||
Labs helping you to dive into CloudFormation. Start from ``stubs`` have a look at ``solutions`` or ask your instructor if you need help. | ||
Labs helping you to learn AWS CloudFormation within a day. | ||
|
||
## Resources | ||
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html | ||
## Setup | ||
Clone this repository on your local machine. | ||
|
||
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html | ||
``git clone https://github.com/widdix/learn-cloudformation.git`` | ||
|
||
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html | ||
|
||
|
||
## Highlight | ||
highlight -S js -O rtf --style night --font-size 30 presentations/7-nested.json | pbcopy | ||
Open the AWS Management Console of an empty AWS account. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Lab 0: Create a CloudFormation stack | ||
|
||
Create a CloudFormation stack based on an existing template. | ||
|
||
## Overview | ||
1. Create a CloudFormation stack based on an existing template. | ||
|
||
## Instructions | ||
1. Open [CloudFormation](https://console.aws.amazon.com/cloudformation) in AWS Management Console. | ||
1. Click **Create Stack** button. | ||
1. Select **Upload a template to Amazon S3**. | ||
1. Choose file ``learn-cloudformation/lab0-create-stack/demo.json``. | ||
1. Click **Next** button. | ||
1. Insert ``lab0-$username``as stack name. Replace ``$username``with your username (e.g. lab0-awittig). | ||
1. Select a random subnet and the only available VPC as **Parameters**. | ||
1. Click **Next** button. | ||
1. Skip next step by clicking on **Next** button. | ||
1. Review your input and click **Create** button. | ||
1. Wait until your stack reaches status **CREATE_COMPLETE**. | ||
1. Select your stack by clicking on row of the table. | ||
1. Switch to the **Outputs** tab. | ||
1. Search for **HelloWorldURL* and click on the URL. | ||
1. A website showing ``Hello World!`` should appear. | ||
1. Select your stack by clicking on row of the table again. | ||
1. Select **Delete Stack** from the **Actions** menu. | ||
1. Confirm the deletion of your stack. | ||
1. Congratulations! You are done with the lab! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Description": "Hello World! example", | ||
"Parameters": { | ||
"VPC": { | ||
"Description": "The default VPC", | ||
"Type": "AWS::EC2::VPC::Id" | ||
}, | ||
"Subnet": { | ||
"Description": "A public subnet from default VPC.", | ||
"Type": "AWS::EC2::Subnet::Id" | ||
} | ||
}, | ||
"Mappings": { | ||
"RegionMap": { | ||
"eu-west-1": {"AMI": "ami-bff32ccc"}, | ||
"ap-southeast-1": {"AMI": "ami-c9b572aa"}, | ||
"ap-southeast-2": {"AMI": "ami-48d38c2b"}, | ||
"eu-central-1": {"AMI": "ami-bc5b48d0"}, | ||
"ap-northeast-2": {"AMI": "ami-249b554a"}, | ||
"ap-northeast-1": {"AMI": "ami-383c1956"}, | ||
"us-east-1": {"AMI": "ami-60b6c60a"}, | ||
"sa-east-1": {"AMI": "ami-6817af04"}, | ||
"us-west-1": {"AMI": "ami-d5ea86b5"}, | ||
"us-west-2": {"AMI": "ami-f0091d91"} | ||
} | ||
}, | ||
"Resources": { | ||
"EC2Instance": { | ||
"Type": "AWS::EC2::Instance", | ||
"Properties": { | ||
"ImageId": {"Fn::FindInMap": ["RegionMap", {"Ref": "AWS::Region"}, "AMI"]}, | ||
"InstanceType": "t2.micro", | ||
"NetworkInterfaces": [{ | ||
"AssociatePublicIpAddress": "true", | ||
"DeviceIndex": "0", | ||
"GroupSet": [{"Ref": "WebserverSecurityGroup"}], | ||
"SubnetId": {"Ref": "Subnet"} | ||
}], | ||
"Tags": [{ | ||
"Key": "Name", | ||
"Value": "hello-world" | ||
}], | ||
"UserData": {"Fn::Base64": {"Fn::Join": ["", [ | ||
"#!/bin/bash -ex\n", | ||
"yum install -y httpd\n", | ||
"cd /var/www/html\n", | ||
"echo '<html><body>Hello World!</body></html>' > index.html\n", | ||
"service httpd start\n" | ||
]]}} | ||
} | ||
}, | ||
"WebserverSecurityGroup": { | ||
"Type": "AWS::EC2::SecurityGroup", | ||
"Properties": { | ||
"GroupDescription": "hello-world-webserver", | ||
"VpcId": {"Ref": "VPC"}, | ||
"SecurityGroupIngress": [{ | ||
"CidrIp": "0.0.0.0/0", | ||
"FromPort": 80, | ||
"IpProtocol": "tcp", | ||
"ToPort": 80 | ||
}] | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"HelloWorldURL": { | ||
"Description": "The URL pointing to Hello World!.", | ||
"Value": {"Fn::Join": ["", ["http://", {"Fn::GetAtt": ["EC2Instance", "PublicDnsName"]}]]} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Lab 1: Simple template | ||
|
||
Create a S3 bucket with the help of CloudFormation. | ||
|
||
## Overview | ||
1. Create a CloudFormation template that will create a S3 bucket named learn-cloudformation-$username. Replace $username with your username (e.g. awittig). | ||
1. Create a CloudFormation stack based on your template. | ||
|
||
## Instructions | ||
|
||
## Create a template | ||
1. Open ``stub.json`` with an editor of your choice. The stub file contains a skeleton to start from. | ||
1. Add an ``AWSTemplateFormatVersion`` definition to your template (see [Template anatomy](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html)). | ||
1. Add a ``Description`` to your template (see [Template anatomy](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html)). | ||
1. Add a ``Resources`` section to your template (see [Template anatomy](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html)). | ||
1. Add a **S3 bucket** to the ``Resources`` section of your template (see [Resource Type: S3 bucket](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html)). | ||
1. Add ``BucketName`` as the only property to the ``Properties`` section of the S3 bucket. Be careful: bucket name has to be globally unique. Try ``learn-cloudformation-$username`` replace ``$username`` with your username. | ||
|
||
## Create a stack based on the template | ||
1. Open [CloudFormation](https://console.aws.amazon.com/cloudformation) in AWS Management Console. | ||
1. Click **Create Stack** button. | ||
1. Select **Upload a template to Amazon S3**. | ||
1. Choose the template file you created for this lab. | ||
1. Click **Next** button. | ||
1. Insert ``lab1-$username`` as stack name. Replace ``$username``with your username (e.g. lab1-awittig). | ||
1. Click **Next** button. | ||
1. Skip next step by clicking on **Next** button. | ||
1. Review your input and click **Create** button. | ||
1. Wait until your stack reaches status **CREATE_COMPLETE**. | ||
1. Select your stack by clicking on row of the table. | ||
1. Select **Delete Stack** from the **Actions** menu. | ||
1. Confirm the deletion of your stack. | ||
1. Congratulations! You are done with the lab! | ||
|
||
## Documentation | ||
* [Template anatomy](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html) | ||
* [Resource Type: S3 bucket](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html) | ||
|
||
## Sample solution | ||
This lab includes a sample solution ``sample-solution.json``. Use it if you are stuck during the creation of your template of if you want to review your results. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Description": "Simple S3 bucket", | ||
"Resources": { | ||
"S3Bucket": { | ||
"Type" : "AWS::S3::Bucket", | ||
"Properties": { | ||
"BucketName": "learn-cloudformation-$username" | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Lab 2: Using parameters | ||
|
||
Use input parameters to be able to re-use CloudFormation templates- | ||
|
||
## Overview | ||
1. Create a CloudFormation template accepting input parameters and using them to configure an EC2 instance. | ||
1. Create a CloudFormation stack based on your template. | ||
|
||
## Instructions | ||
|
||
## Create a template | ||
1. Open ``stub.json`` with an editor of your choice. The stub file contains a skeleton to start from. | ||
1. Add a parameter called ``AMI`` of type ``String`` to the ``Parameters`` section (see [Parameters section](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html)). | ||
1. Add a parameter called ``InstanceType`` of type ``String`` to the ``Parameters`` section (see [Parameters section](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html)). | ||
1. Add a parameter called ``Subnet`` of type ``AWS::EC2::Subnet::Id`` to the ``Parameters`` section (see [Parameters section](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html)). | ||
|
||
|
||
## Create a stack based on the template | ||
1. Open [CloudFormation](https://console.aws.amazon.com/cloudformation) in AWS Management Console. | ||
1. Click **Create Stack** button. | ||
1. Select **Upload a template to Amazon S3**. | ||
1. Choose the template file you created for this lab. | ||
1. Click **Next** button. | ||
1. Insert ``lab2-$username``as stack name. Replace ``$username``with your username (e.g. lab2-awittig). | ||
1. Select a random subnet as parameter for **Subnet**. | ||
1. Insert ``t2.micro`` as parameter for **InstanceType**. | ||
1. Insert ``ami-bff32ccc`` (eu-west-1) or ``ami-bc5b48d0``(eu-central-1) as parameter for **AMI**. | ||
1. Click **Next** button. | ||
1. Skip next step by clicking on **Next** button. | ||
1. Review your input and click **Create** button. | ||
1. Wait until your stack reaches status **CREATE_COMPLETE**. | ||
1. Select your stack by clicking on row of the table. | ||
1. Select **Delete Stack** from the **Actions** menu. | ||
1. Confirm the deletion of your stack. | ||
1. Congratulations! You are done with the lab! | ||
|
||
## Documentation | ||
* [Template anatomy](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html) | ||
* [Resource Type: EC2 instance](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html) | ||
|
||
## Sample solution | ||
This lab includes a sample solution ``sample-solution.json``. Use it if you are stuck during the creation of your template of if you want to review your results. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Lab 3: Using build-in functions | ||
|
||
Use input parameters to be able to re-use CloudFormation templates- | ||
|
||
## Overview | ||
1. Create a CloudFormation template using build-in functions ``Fn::Base64`` and ``Fn::Join``. | ||
1. Create a CloudFormation stack based on your template. | ||
|
||
## Instructions | ||
|
||
## Create a template | ||
1. Open ``stub.json`` with an editor of your choice. The stub file contains a skeleton to start from. | ||
1. Use functions ``Fn::Base64`` and ``Fn::Join`` to combine the following Bash script and inject it into the EC2 instance with the help of ``UserData``. $URL needs to be replaced with the template parameter named ``URL`` (see [Build-in functions](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html)). | ||
|
||
|
||
Bash script installing httpd-tools and running a small HTTP load test. | ||
|
||
``` | ||
#!/bin/bash -ex | ||
yum install -y httpd-tools | ||
ab -n 1000 -c 4 $URL | ||
``` | ||
|
||
|
||
## Create a stack based on the template | ||
1. Open [CloudFormation](https://console.aws.amazon.com/cloudformation) in AWS Management Console. | ||
1. Click **Create Stack** button. | ||
1. Select **Upload a template to Amazon S3**. | ||
1. Choose the template file you created for this lab. | ||
1. Click **Next** button. | ||
1. Insert ``lab3-$username``as stack name. Replace ``$username``with your username (e.g. lab3-awittig). | ||
1. Select a random subnet as parameter for **Subnet**. | ||
1. Insert ``t2.micro`` as parameter for **InstanceType**. | ||
1. Insert ``ami-bff32ccc`` (eu-west-1) or ``ami-bc5b48d0``(eu-central-1) as parameter for **AMI**. | ||
1. Insert ``http://widdix.net/`` or a website you own for **URL**. | ||
1. Click **Next** button. | ||
1. Skip next step by clicking on **Next** button. | ||
1. Review your input and click **Create** button. | ||
1. Wait until your stack reaches status **CREATE_COMPLETE**. | ||
1. Select your stack by clicking on row of the table. | ||
1. Select **Delete Stack** from the **Actions** menu. | ||
1. Confirm the deletion of your stack. | ||
1. Congratulations! You are done with the lab! | ||
|
||
## Documentation | ||
[Build-in functions](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html) | ||
|
||
## Sample solution | ||
This lab includes a sample solution ``sample-solution.json``. Use it if you are stuck during the creation of your template of if you want to review your results. |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Lab 4: Outputs | ||
|
||
Use outputs to get access to informations about the resources created by a stack. | ||
|
||
## Overview | ||
1. Create a CloudFormation template using outputs. | ||
1. Create a CloudFormation stack based on your template. | ||
|
||
## Instructions | ||
|
||
## Create a template | ||
1. Open ``stub.json`` with an editor of your choice. The stub file contains a skeleton to start from. | ||
1. Add ``InstanceId`` containing the instance-id of the EC2 instance to the outputs section (see [Outputs section](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html) and [Resource Type: EC2 instance](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html)). | ||
1. Add ``PublicIPAddress`` containing the public IP address of the EC2 instance to the outputs section: [Outputs section](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html) and [Resource Type: EC2 instance](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html)). | ||
|
||
## Create a stack based on the template | ||
1. Open [CloudFormation](https://console.aws.amazon.com/cloudformation) in AWS Management Console. | ||
1. Click **Create Stack** button. | ||
1. Select **Upload a template to Amazon S3**. | ||
1. Choose the template file you created for this lab. | ||
1. Click **Next** button. | ||
1. Insert ``lab4-$username``as stack name. Replace ``$username``with your username (e.g. lab4-awittig). | ||
1. Select a random subnet as parameter for **Subnet**. | ||
1. Insert ``t2.micro`` as parameter for **InstanceType**. | ||
1. Insert ``ami-bff32ccc`` (eu-west-1) or ``ami-bc5b48d0``(eu-central-1) as parameter for **AMI**. | ||
1. Insert ``http://widdix.net/`` or a website you own for **URL**. | ||
1. Click **Next** button. | ||
1. Skip next step by clicking on **Next** button. | ||
1. Review your input and click **Create** button. | ||
1. Wait until your stack reaches status **CREATE_COMPLETE**. | ||
1. Select your stack by clicking on row of the table. | ||
1. Change to the **Outputs** tab. | ||
1. Find value of ``InstanceId`` and note it down. | ||
1. Select the **EC2 service** from the main navigation. | ||
1. Search for an EC2 instance with the instance id from the outputs tab. | ||
1. Select the EC2 instance by clicking on the row of the table. | ||
1. Select the action **Get System Log** from the **Actions** menu hidden under **Instance Settings**. | ||
1. You will find the outputs from the load test in the logs. | ||
1. Switch back to the CloudFormation service. | ||
1. Select your stack by clicking on row of the table. | ||
1. Select **Delete Stack** from the **Actions** menu. | ||
1. Confirm the deletion of your stack. | ||
1. Congratulations! You are done with the lab! | ||
|
||
## Documentation | ||
* [Outputs section](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html) | ||
* [Resource Type: EC2 instance](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html) | ||
|
||
## Sample solution | ||
This lab includes a sample solution ``sample-solution.json``. Use it if you are stuck during the creation of your template of if you want to review your results. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Lab 5: Dependencies between resources | ||
|
||
CloudFormation detects dependencies between resources and creates, updates, or deletes the resources in the correct order. | ||
|
||
## Overview | ||
1. Create a CloudFormation template defining dependencies between resources. | ||
1. Create a CloudFormation stack based on your template. | ||
|
||
## Instructions | ||
|
||
## Create a template | ||
1. Open ``stub.json`` with an editor of your choice. The stub file contains a skeleton to start from. | ||
1. Add a reference to ``SecurityGroup`` to the list of ``SecurityGroupIds`` of the EC2 instance (see [Reference function](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)). | ||
1. Add a reference to ``KeyName`` (parameter) to the ``KeyName``of the EC2 instance (see [Reference function](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)). | ||
|
||
## Create a stack based on the template | ||
1. Open [CloudFormation](https://console.aws.amazon.com/cloudformation) in AWS Management Console. | ||
1. Click **Create Stack** button. | ||
1. Select **Upload a template to Amazon S3**. | ||
1. Choose the template file you created for this lab. | ||
1. Click **Next** button. | ||
1. Insert ``lab5-$username``as stack name. Replace ``$username``with your username (e.g. lab5-awittig). | ||
1. Select a random subnet as parameter for **Subnet**. | ||
1. Select a random key as parameter for **Key Pair**. | ||
1. Insert ``ami-bff32ccc`` (eu-west-1) or ``ami-bc5b48d0``(eu-central-1) as parameter for **AMI**. | ||
1. Insert ``http://widdix.net/`` or a website you own for **URL**. | ||
1. Click **Next** button. | ||
1. Skip next step by clicking on **Next** button. | ||
1. Review your input and click **Create** button. | ||
1. Wait until your stack reaches status **CREATE_COMPLETE**. | ||
1. Select your stack by clicking on row of the table. | ||
1. Change to the **Outputs** tab. | ||
1. Find value of ``InstanceId`` and note it down. | ||
1. Select the **EC2 service** from the main navigation. | ||
1. Search for an EC2 instance with the instance id from the outputs tab. | ||
1. Select the EC2 instance by clicking on the row of the table. | ||
1. Search for the Security Group attached to the EC2 instance and check if it allows incoming traffic to port 22. | ||
1. Switch back to the CloudFormation service. | ||
1. Select your stack by clicking on row of the table. | ||
1. Select **Delete Stack** from the **Actions** menu. | ||
1. Confirm the deletion of your stack. | ||
1. Congratulations! You are done with the lab! | ||
|
||
## Documentation | ||
* [Reference function](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html) | ||
|
||
## Sample solution | ||
This lab includes a sample solution ``sample-solution.json``. Use it if you are stuck during the creation of your template of if you want to review your results. |
File renamed without changes.
Oops, something went wrong.