AWS CloudFormation: Create a Stack

Deploy infrastructure with aws cloudformation create-stack. Provide templates, parameters, capabilities, and tags for repeatable deployments.

CloudFormation Operations

Detailed Explanation

Creating CloudFormation Stacks

CloudFormation stacks are collections of AWS resources defined in a template (YAML or JSON). The create-stack command deploys a template to provision resources.

Basic Stack Creation

aws cloudformation create-stack \
  --stack-name my-app-stack \
  --template-body file://template.yaml

With Parameters

aws cloudformation create-stack \
  --stack-name production-stack \
  --template-body file://template.yaml \
  --parameters \
    ParameterKey=Environment,ParameterValue=production \
    ParameterKey=InstanceType,ParameterValue=t3.medium \
    ParameterKey=KeyPairName,ParameterValue=my-key

With IAM Capabilities

aws cloudformation create-stack \
  --stack-name iam-stack \
  --template-body file://template.yaml \
  --capabilities CAPABILITY_NAMED_IAM

Templates that create IAM resources require explicit acknowledgment via --capabilities:

  • CAPABILITY_IAM — for IAM resources with auto-generated names
  • CAPABILITY_NAMED_IAM — for IAM resources with custom names
  • CAPABILITY_AUTO_EXPAND — for macros and nested stacks

With Tags

aws cloudformation create-stack \
  --stack-name my-stack \
  --template-body file://template.yaml \
  --tags \
    Key=Environment,Value=production \
    Key=Team,Value=backend \
    Key=CostCenter,Value=CC-1234

Tags are propagated to all resources created by the stack.

Template from S3

aws cloudformation create-stack \
  --stack-name my-stack \
  --template-url https://s3.amazonaws.com/my-templates/template.yaml

Monitor Stack Creation

aws cloudformation wait stack-create-complete --stack-name my-stack
aws cloudformation describe-stack-events \
  --stack-name my-stack \
  --query "StackEvents[].[Timestamp,ResourceType,ResourceStatus,ResourceStatusReason]" \
  --output table

The wait command blocks until the stack reaches CREATE_COMPLETE or fails.

Use Case

Deploying repeatable infrastructure for multi-environment applications, provisioning VPCs with subnets and security groups, creating serverless application stacks, or setting up CI/CD infrastructure.

Try It — AWS CLI Command Builder

Open full tool