How to model Infrastructure as Code as part of CI / CD, incorporating it into your standard application development lifecycle, execute infrastructure changes in your CI/CD pipeline, and get additional benefits, such as reducing configuration errors and provisioning faster. All this leveraging IaC Tools on AWS like AWS CloudFormation, AWS SAM & AWS CDK
4. Managing Infrastructure as Code
SOURCE
Developers
commit changes
BUILD
Changes
are built
STAGING
Code is deployed and
tested
PRODUCTION
Developers commit
changes
AWS CodeCommit AWS CodeBuild Third Party Tooling AWS CodeDeploy
AWS CodePipeline
AWS CodeDeploy
8. AWS CloudFormation
• Create and provision AWS infrastructure deployments
predictably and repeatedly
• Resources are written in text files using JSON or YAML
format. Use Cloud9 or your favorite editor
• Version Control the template
• Helps build the specified services in safe, repeatable
manner
15. AWS Serverless Application Model
• AWS CloudFormation extension, optimized for serverless
• AWS SAM is supported directly by AWS CloudFormation
• YAML or JSON
• Supported Resources
• Api, Application, Function, HttpApi, LayerVersion, SimpleTable,
StateMachine
c
16. AWS SAM Template Anatomy
• Transform declaration
Transform: AWS::Serverless-2016-10-31
• Globals section
AWS::Serverless::Function, AWS::Serverless::Api, etc.
• Resources section
Combination of CloudFormation & AWS SAM resources
• Parameters section
Objects declared in Parameters section cause SAM deploy
17. AWS SAM CLI
• CLI tool for local development, debugging, testing, deploying, and monitoring of
serverless applications
• Supports API Gateway “proxy-style” and Lambda service API testing
• Response object and function logs available on your local machine
• Uses open-source docker-lambda images to mimic Lambda’s execution environment
• Can tail production logs from CloudWatch logs
• Can help you build in native dependencies
18. AWS SAM CLI Commands
• sam build – install dependencies
• sam deploy – deploy AWS SAM application with AWS CloudFormation
• sam init – initialize a serverless application
• sam local:
• generate-event– generate sample payloads from event sources
• Invoke invokes a Lambda function once
• start-api – set up local endpoint to test your API
• start-lambda – start a local endpoint to test your local lambda
• sam logs – fetch logs for a function
• sam package – package an AWS SAM application
• sam publish – Publish an AWS SAM application to the AWS Serverless Application Repository
• sam validate – Verifies whether an AWS SAM template file is valid
21. AWS CDK
• AWS CDK to define your cloud resources in a familiar
programming language
• AWS CDK supports TypeScript, JavaScript, Python, Java,
C#/.Net, and (in developer preview) Go
• Define reusable cloud components known as Constructs
• Compose Constructs together into Stacks and Apps
24. AWS CDK Development Workflow
Create App Add Code Build Synthesize Deploy
Add code to the app to create
resources within stacks
Build the app
Synthesize stack(s) in app to
create AWS CloudFormation
template Deploy stacks to
your AWS account
25. AWS CDK Toolkit
The AWS CDK Toolkit is a command line tool for interacting with CDK apps
• cdk lists (ls) – Lists the stacks in the app
• cdk synthesize (synth) – Synthesizes and prints the CloudFormation template for the specified
stack(s)
• cdk bootstrap – Deploys the CDK Toolkit stack
• cdk deploy - Deploys the specified stack(s)
• cdk destroy - Destroys the specified stack(s)
• cdk diff – Compares the stack with deployed or local CloudFormation template
• cdk metadata – Displays metadata about the specified stack
• cdk init – Creates a new CDK project in the current directory from a specified template
• cdk context - Manages cached context values
• cdk docs (doc) – Opens the CDK API reference in your browser
• cdk doctor - Checks your CDK project for potential problems