In this step, you will deploy the complete AWS infrastructure using CloudFormation template. The template will create VPC, subnets, EC2 instances, RDS database, Load Balancer, S3 buckets, CloudFront distribution, and all necessary resources.
Before deployment, validate the template to ensure no syntax errors:
cd aws
aws cloudformation validate-template \
--template-body file://infrastructure.yaml \
--region ap-southeast-1
Expected result: Information about parameters, outputs, and template description.
Windows:
cd aws
deploy.bat create
Linux/Mac:
cd aws
chmod +x deploy.sh
./deploy.sh create
The script will automatically:
aws cloudformation create-stack \
--stack-name workshop-aws-dev \
--template-body file://infrastructure.yaml \
--parameters file://parameters.json \
--capabilities CAPABILITY_NAMED_IAM \
--region ap-southeast-1
workshop-aws-dev# Check status
aws cloudformation describe-stacks \
--stack-name workshop-aws-dev \
--region ap-southeast-1 \
--query 'Stacks[0].StackStatus'
# View events
aws cloudformation describe-stack-events \
--stack-name workshop-aws-dev \
--region ap-southeast-1 \
--max-items 10
Stack creation takes approximately 15-20 minutes:
After stack creation succeeds (Status: CREATE_COMPLETE), get outputs:
aws cloudformation describe-stacks \
--stack-name workshop-aws-dev \
--region ap-southeast-1 \
--query 'Stacks[0].Outputs' \
--output table
Important Outputs:
| Output Key | Description | Example |
|---|---|---|
VPCId | VPC ID | vpc-0123456789abcdef0 |
FrontendBucketName | S3 bucket for frontend | workshop-aws-dev-frontend-123456789012-ap-southeast-1 |
CloudFrontDomainName | CloudFront URL | d1234567890abc.cloudfront.net |
ALBDNSName | Load Balancer DNS | workshop-aws-dev-alb-123456789.ap-southeast-1.elb.amazonaws.com |
RDSEndpoint | Database endpoint | workshop-aws-dev-db.xxxxx.ap-southeast-1.rds.amazonaws.com |
APIGatewayURL | API Gateway URL | https://xxxxx.execute-api.ap-southeast-1.amazonaws.com/dev |
CognitoUserPoolId | Cognito User Pool ID | ap-southeast-1_xxxxxxxxx |
Save these values - you’ll need them for next steps!
# Get VPC ID
VPC_ID=$(aws cloudformation describe-stacks \
--stack-name workshop-aws-dev \
--region ap-southeast-1 \
--query 'Stacks[0].Outputs[?OutputKey==`VPCId`].OutputValue' \
--output text)
# View VPC details
aws ec2 describe-vpcs --vpc-ids $VPC_ID --region ap-southeast-1
# View Subnets
aws ec2 describe-subnets \
--filters "Name=vpc-id,Values=$VPC_ID" \
--region ap-southeast-1 \
--query 'Subnets[*].[SubnetId,CidrBlock,AvailabilityZone,Tags[?Key==`Name`].Value|[0]]' \
--output table
# View EC2 instances in Auto Scaling Group
aws ec2 describe-instances \
--filters "Name=tag:aws:cloudformation:stack-name,Values=workshop-aws-dev" \
--region ap-southeast-1 \
--query 'Reservations[*].Instances[*].[InstanceId,State.Name,PrivateIpAddress,PublicIpAddress]' \
--output table
# View RDS instance
aws rds describe-db-instances \
--db-instance-identifier workshop-aws-dev-db \
--region ap-southeast-1 \
--query 'DBInstances[0].[DBInstanceIdentifier,DBInstanceStatus,Endpoint.Address,Endpoint.Port]' \
--output table
If stack creation fails:
aws cloudformation describe-stack-events \
--stack-name workshop-aws-dev \
--region ap-southeast-1 \
--query 'StackEvents[?ResourceStatus==`CREATE_FAILED`].[LogicalResourceId,ResourceStatusReason]' \
--output table
Error: “Key pair does not exist”
parameters.jsonError: “Invalid AMI ID”
infrastructure.yamlError: “Insufficient permissions”
# Delete failed stack
aws cloudformation delete-stack \
--stack-name workshop-aws-dev \
--region ap-southeast-1
# Wait for stack deletion
aws cloudformation wait stack-delete-complete \
--stack-name workshop-aws-dev \
--region ap-southeast-1
# Try creating again
aws cloudformation create-stack \
--stack-name workshop-aws-dev \
--template-body file://infrastructure.yaml \
--parameters file://parameters.json \
--capabilities CAPABILITY_NAMED_IAM \
--region ap-southeast-1
Checklist to confirm infrastructure is ready:
CREATE_COMPLETErunning)availableactiveDeployedAfter infrastructure is ready, you can: