AWS Builders Online Series
Deploy Infrastructure
as a Code on AWS
Nelli Lovchikova
Solutions Architect Manager
Amazon Web Services
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Agenda
1. Infrastructure as a code (IaC) overview
2. AWS CloudFormation
3. AWS Cloud Development Kit (AWS CDK)
4. Terraform with AWS CDK
5. Recap
6. Next steps – resources to get started
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Challenge: Environmental Drift
• Each environment maintains individual settings
• Snowflake effect
• Causes by
• Manual changes
• Poor configuration
• Application mischief
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Challenge: Human Error
• Idempotence – same operation produces the same result
• Lost knowledge
• Emergency situations
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Infrastructure as a code (IaC)
Consistent Lower risk of Lower cost Self-documented
human error
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Evolution of Infrastructure as Code (IaC)
Abstractions
Generators
Declarative
Scripted AWS CDK
Troposphere Pulumi
Manual GoFormation
AWS CloudFormation
#!/bin/bash Terraform
Wikis, playbooks,
ask-Bob-he-knows
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS CloudFormation
Upload local files or Stacks and resources are
Code in YAML or JSON
from an Amazon S3 provisioned as a running
directly or use sample
bucket environment
templates
Create stack
using API via AWS
CloudFormation
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Cloud Development Kit (CDK)
App
Stack (s)
Construct Construct
AWS Lambda Amazon Amazon Amazon S3
DynamoDB SQS Bucket
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Development workflow
execute synthesize deploy provision
AWS CDK AWS CDK Template and AWS
Cloud Resources
Source Code CLI assets CloudFormation
📙 cdk init // create new project
🛠 npm run build // build project
🧬 cdk synth // create templates and assets
🔎 cdk diff // check what will change
🚀 cdk deploy // push changes to your account
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Construct levels
L3 Patterns
L2 AWS Constructs
L1 AWS CloudFormation resources
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Level 1
cdk synth
• Generated mappings from CloudFormation Specification
• abc.CfnXyz → AWS::ABC::XYZ CloudFormation Resource
• ec2.CfnInstance → AWS::EC2::Instance
• kms.CfnKey → AWS::KMS::Key
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Level 2
• Ready-to-use VPC setup
cdk synth • 65536 IPs split equally between 4 subnets
• If you provide a region → adjusted to 3 AZs
• Everything is optional, change any parameter
• Sane default values
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Level 3
AWS VPC Elastic Load Balancer AWS Fargate Amazon ECS task
definition
• Subnets • Security group • IAM roles • Image
829 line Security group egress • CPU
• EIP • • IAM policies
AWS CloudFormation Security group ingress • Memory
• NAT gateways • • Log group
template • Port
“amazon-ecs-sample”
• Internet gateway • Task definition • Configuration
• Listener
image
• Route
• Route table • Target group
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Terraform
Terraform
provider
Target API
Terraform
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Terraform configuration
A Terraform configuration is a
complete document in the
Terraform language that tells
Terraform how to manage a given
collection of infrastructure.
A configuration can consist of
multiple files and directories.
Key concepts: Providers,
resources, variables, outputs, and
modules.
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS CDK supports Terraform
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Conclusion
• Infrastructure as a code and it’s evolution
• AWS CloudFormation
• AWS CDK – concepts, levels and abstractions
• Terraform
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Next steps: Get hands-on
1. https://github.com/aws-cloudformation
2. https://github.com/aws/aws-cdk
3. https://github.com/aws-samples/aws-cdk-examples
4. https://cdkworkshop.com/
5. https://docs.aws.amazon.com/cdk/api/v2/docs/aws-construct-library.html
6. https://cdkworkshop.com/20-typescript/70-advanced-topics/200-pipelines/2000-create-repo.html
7. https://www.hashicorp.com/blog/cdk-for-terraform-now-generally-available
8. https://developer.hashicorp.com/terraform/tutorials/cdktf
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Visit the AWS Modern Applications Resource Hub
Dive deeper with these resources to help you innovate fast, reduce risk, and accelerate time to market
• Build modern applications on AWS
• Building event-driven architectures on AWS
• Seamless Kubernetes on premises and in the cloud
• Unlock digital transformation by modernizing with containers
• Unleash the power of modern apps with generative AI on AWS
• Accelerate full-stack web and mobile app development on AWS https://tinyurl.com/modern-apps-aws
• Determining the total cost of ownership: Comparing serverless and server-based
technologies
… and more!
Visit resource hub
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS Training & Certification
Access 600+ free digital courses with AWS Skill Builder
Focus on the cloud skills and services that are most
relevant to you across 30+ AWS solutions, including
digital self-paced learning plans and ramp-up guides
• Build your future in the AWS Cloud at your own pace
https://skillbuilder.aws/
• Advance your skills and knowledge with learning plans
• Validate your cloud expertise with AWS Certification
BUILD IN-DEMAND CLOUD SKILLS
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you for attending
AWS Builders Online Series
We hope you found it interesting! A kind reminder to complete the survey.
Let us know what you thought of today’s event and how we can improve the event
experience for you in the future.
[email protected]
twitter.com/AWSCloud
facebook.com/AmazonWebServices
youtube.com/user/AmazonWebServices
linkedin.com/company/amazon-web-services
twitch.tv/aws
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Thank you!
Nelli Lovchikova
Solutions Architect Manager
Amazon Web Services
© 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved.