Prompt Engineering for Infrastructure
The file auto_scaling_web_app.yaml was not written by hand. It was generated entirely by the Amazon Q IDE extension using the following prompt workflow.
Step 1: Generating the Code
Developer typed into the Amazon Q chat window:
"Write a complete CloudFormation template in YAML that provisions a highly available web architecture. I need an Application Load Balancer facing the public internet on port 80. The ALB should route traffic to an Auto Scaling Group containing EC2 t3.micro instances running Amazon Linux. Ensure the instances install an Apache web server on boot using UserData."
Result: Amazon Q generated 95% of the file perfectly.
Step 2: Refining the Code
Developer highlighted the Security Groups section and asked:
"Update these security groups so that the EC2 instances are completely blocked from the public internet. They should only accept HTTP traffic that originates directly from the Load Balancer."
Result: Amazon Q updated WebServerSecurityGroup to use SourceSecurityGroupId instead of a public 0.0.0.0/0 CIDR block.
Step 3: Terminal Diagnostics
The developer attempted to deploy the template using the AWS CLI, but intentionally misspelled a flag:
aws cloudformation deploy --templeet-file auto_scaling_web_app.yaml --stack-name prod
The terminal threw a nasty validation error.
The developer simply typed: q
Result: Amazon Q CLI read the error message instantly and replied:
"It looks like you misspelled the
--template-fileparameter in your AWS CLI command. Would you like me to run the corrected command for you?"