This nested CloudFormation template creates EC2 instances within a VPC that includes both public and private subnets. It manages the infrastructure by creating multiple nested stacks for the VPC, NAT Gateway, route tables, security groups and EC2 instances.
- An AWS account with permissions to create VPC, EC2, S3, and CloudFormation resources.
- AWS CLI or AWS Management Console to deploy the template.
- Access to an S3 bucket where you'll upload the nested stack templates for use during deployment.
- AWSTemplateFormatVersion: The version of the template format.
- Description: A description of the template and its functionality.
- Parameters: Inputs required for the template to customize the stack according to your requirements.
- Resources: AWS resources that will be created.
- Outputs: Values that will be outputted after deployment.
Before deploying, ensure your AWS CLI is configured to use a specified profile:
aws configure --profile your-profile-name
📝 Replace
your-profile-name
with the appropriate profile that has the necessary permissions.
git clone https://github.com/NT548-P11-DevOps-Technology/assignment-lab01-cloudformation.git
To deploy nested CloudFormation stacks, you must upload the templates to an S3 bucket. You can use the following steps to upload templates from your local system to an S3 bucket:
-
Modify the S3 bucket name in the aws-s3-cp.sh (Linux) or aws-s3-cp.bat (Windows) scripts.
Replace the S3_BUCKET placeholder in the script with your actual S3 bucket name:
S3_BUCKET=your-bucket-name
-
Run the respective script depending on your operating system:
- For Linux/Mac:
bash aws-s3-cp.sh
- For Windows:
.\aws-s3-cp.bat
This will upload all the nested stack templates to your S3 bucket.
To deploy the stack, use the following AWS CLI command to launch the CloudFormation template from your S3 bucket:
aws cloudformation deploy --template-file ./root_stack.yml --stack-name your-stack-name --profile your-profile-name
Note:
your-stack-name
: A name for the CloudFormation stack.your-bucket-name
: The name of your S3 bucket where the templates are stored.your-profile-name
: The AWS CLI profile that has the appropriate permissions to create the stack.
Once the stack creation starts, you can monitor its progress from the AWS Management Console or using the AWS CLI:
aws cloudformation describe-stacks --stack-name your-stack-name --profile your-profile-name
You can also check the AWS CloudFormation console for detailed information about the stack's status and to troubleshoot any errors.
When working with security groups, it's essential to customize the SSHLocation
parameter in the security groups template to allow SSH access from your specific public IP address. The default setting in this template is a placeholder (103.129.191.120/32
), which should be replaced with your own public IP address to ensure that only authorized users can access your EC2 instances over SSH.
Find your public IP address via Google search "What is my IP?" or enter this command in your terminal:
curl ifconfig.io