AWS/CloudFormation

From r00tedvw.com wiki
Jump to: navigation, search

Quick Reference | AWS CLI | CloudFormation

Contents

 [hide

AWS Cloudformation CLI

Testing template

https://docs.aws.amazon.com/cli/latest/reference/cloudformation/validate-template.html

~$ aws cloudformation validate-template --template-body file://$HOME/s3_ec2.yaml
{
    "CapabilitiesReason": "The following resource(s) require capabilities: [AWS::IAM::Policy]",
    "Capabilities": [
        "CAPABILITY_IAM"
    ],
    "Parameters": [
        {
            "DefaultValue": "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2",
            "NoEcho": false,
            "ParameterKey": "LatestAmiId"
        },
        {
            "NoEcho": false,
            "Description": "Random String",
            "ParameterKey": "Entropy"
        }
    ]
}

Creating stack

https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html

~$ aws cloudformation create-stack --stack-name s3ec2stack01 --template-body file://$HOME/s3_ec2.yaml --parameters ParameterKey=Entropy,ParameterValue=testentropy ParameterKey=BranchName,ParameterValue=testbranch --capabilities CAPABILITY_IAM
{
    "StackId": "arn:aws:cloudformation:us-east-1:548975612458:stack/s3ec2stack01/177a94e0-9923-23et-b86a-0a5462e42a87"
}

Template Examples

S3 Bucket

Here is a CloudFormation Template (in yaml) that I used to create a S3 bucket with the following requirements:

  • Public Read
  • 7 day retention policy
  • Bucket Policy allowing access to all resources.
  • Export the S3 bucket name, Secure URL, and Website URL for usage in other templates.
 [Expand

AWS Template:

Lambda & CloudFront

Here is a CloudFormation Template (in yaml) that I used to create a 2 Lambda functions and a cloudfront distribution with the following requirements:

  • use outputs from S3 bucket stack
  • create lambda functions that will work with lambda edge.
  • setup the needed IAM roles for lambda functions to execute on lambda edge.
  • create cloudfront distribution that uses the lambda edge functions and configures the needed behaviors to use them.
 [Expand

AWS Template:

 [Expand

OriginRequest.js

 [Expand

OriginResponse.js

Personal tools
Namespaces

Variants
Actions
Navigation
Mediawiki