aws cloudformation create-stack --template-body file://example-stack.json --stack-name example-stack
aws cloudformation get-template --stack-name example-stack \
| grep -v "TemplateBody" | head -n -1 > example-stack.running
diff <(jq '.' example-stack.running) <(jq '.' example-stack.json)
aws cloudformation describe-stack-events --stack-name example-stack --output text
aws cloudformation describe-stack-resources --stack-name example-stack --output text
aws ec2 describe-tags --filters Name=resource-type,Values=instance Name=resource-type,Values=i-xxx --output text
aws cloudformation update-stack --template-body file://example-stack.json --stack-name example-stack --output text
arn:aws:cloudformation:us-east-1:xxx:stack/example-stack/xxx
aws cloudformation delete-stack --stack-name example-stack
- Computing -
Lambda
- used for your business logic - Router -
API gateway
- used for route HTTP request data to Lambda function - Database -
DynamoDB
- Autoscale document database - Storage -
S3
- Autoscale file storage service`
- AWS::AccountId
- AWS::NotificationARNs
- AWS::NoValue
- AWS::Region
- AWS::StackId
- AWS::StackName
- AWS::URLSuffix
- AWS::Partition
- AWS::EC2::AvailabilityZone::Name
- AWS::EC2::Image::Id
- AWS::EC2::Instance::Id
- AWS::EC2::KeyPair::KeyName
- AWS::EC2::VPC::Id
- AWS::EC2::Subnet::Id
-
- -> validate it -> start creating resources
- If creating resource failed -> rollback and delete resources, that were created before the failure
Parameters:
InstanceType:
Type: String
Resources:
Ec2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref InstanceType
Parameters:
Environment:
Type: String
AllowedValues: [dev, test, prod]
Parameters:
SubnetCIDR:
Type: String
AllowedPattern: '((\d{1,3})\.){3}\d{1,3}/\d{1,2}'
Parameters:
DockerImageVersion:
Type: String
Default: latest
Mappings:
RegionMap:
us-east-1:
HVM64: ami-0ff8a91507f77f867
HVMG2: ami-0a584ac55a7631c0c
us-west-1:
HVM64: ami-0bdb828fd58c52235
HVMG2: ami-066ee5fd4a9ef77f1
eu-west-1:
HVM64: ami-047bb4163c506cd98
HVMG2: ami-0a7c483d527806435
ap-northeast-1:
HVM64: ami-06cd52961ce9f0d85
HVMG2: ami-053cdd503598e4a9d
ap-southeast-1:
HVM64: ami-08569b978cc4dfa10
HVMG2: ami-0be9df32ae9f92309
Resources:
Ec2Instance:
Type: "AWS::EC2::Instance"
Properties:
ImageId: !FindInMap [RegionMap, !Ref "AWS::Region", HVM64]
-
AWSTemplateFormatVersion: '2010-09-09' Parameters: Env: Default: dev Description: Define the environment (dev, test or prod) Type: String AllowedValues: [dev, test, prod] Conditions: IsProd: !Equals [!Ref Env, 'prod'] Resources: Bucket: Type: "AWS::S3::Bucket" Condition: IsProd
Parameters:
# ...
Resources:
Vpc:
Type: AWS::EC2::VPC
Properties:
# ...
PublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
# ...
# The rest of our resources...
Outputs:
VpcId:
Value: !Ref Vpc
Export:
Name: Vpc
PublicSubnet1Id:
Value: !Ref PublicSubnet1
Export:
Name: PublicSubnet1Id
PublicSubnet2Id:
Value: !Ref PublicSubnet2
Export:
Name: PublicSubnet2Id
PublicSubnet3Id:
Value: !Ref PublicSubnet3
Export:
Name: PublicSubnet3Id
Or
Outputs:
PublicSubnetIds:
Value: !Split [",", !Join [",", [!Ref PublicSubnet1, !Ref PublicSubnet2, !Ref PublicSubnet3] ] ]
Export:
Name: PublicSubnetIds
Resources:
WebTierAsg:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
# Some properties...
VpcZoneIdentifier:
- !ImportValue PublicSubnet1Id
- !ImportValue PublicSubnet2Id
- !ImportValue PublicSubnet3Id
Or
Resoures:
WebTierAsg:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
# Some properties
VpcZoneIdentifier: !ImportValuePublicSubnetIds
Outputs:
DbEndpoint:
Value: !If [ ProdEnv, !GetAttProdDatabase.Endpoint.Address, !If [ TestEnv, !GetAttTestDatabase.Endpoint.Address,!GetAtt.DevDatabase.Endpoint.Address ]]
Export:
Name: DbEndpoint