SlideShare a Scribd company logo
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AWS CloudFormation techniques
from the Dutch trenches
Martijn van Dongen
Chief AWS Technology / AWS APN Ambassador
Binx.io (proudly part of Xebia)
D V C 0 7
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Agenda
CloudFormation Custom Resources
Cfn-lint Custom Rules
Taskcat
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Build
if event['RequestType'] == 'Create' or event['RequestType'] == 'Update’:
client = boto3.client('iam’)
response = client.tag_role(
RoleName=event['ResourceProperties']['RoleName’],
Tags=event['ResourceProperties']['Tags’]
)
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "NA")
elif event['RequestType'] == 'Delete’:
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Add
IAMTaggingFunction:
Type: AWS::Serverless::Function
Properties:
Handler: lambda.lambda_handler
Timeout: 30
Role: !GetAtt 'IAMTaggingFunctionRole.Arn’
Runtime: python3.7
CodeUri: ./build/iamtagging.zip
IAMTaggingFunctionRole:
Type: AWS::IAM::Role
...
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Package
$ tree
├── build
├── src
│ └── iamtagging
│ ├── cfnresponse.py
│ ├── lambda.py
│ └── requirements.txt
$ docker run 
-v $(pwd)/src:/src 
-v $(pwd)/build:/build 
binxio/python-lambda-packager:3.7
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Use
TeamRoleTags:
Type: Custom::IAMTagging
Properties:
ServiceToken:
!GetAtt IAMTaggingFunction.Arn
RoleName: !Ref TeamRedRole
Tags:
- Key: Project
Value: Alexa
- Key: CostCenter
Value: 382
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Deploy
$ aws cloudformation package 
--template-file template.yml 
--s3-bucket mys3bucket 
--output-template-file packaged.yml
...
$ aws cloudformation deploy 
--template-file packaged.yml 
--capabilities CAPABILITY_IAM 
--stack-name iamtag
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1
2
3
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
To Production
TeamRoleTags:
Type: AWS::IAM::Tags
Properties:
ServiceToken:
!GetAtt IAMTaggingFunction.Arn
RoleName: !Ref TeamRedRole
Tags:
- Key: Project
Value: Alexa
- Key: CostCenter
Value: 0382
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Example Extension: Secret Provider
DBPassword:
Type: Custom::Secret
Properties:
Name: /demo/PGPASSWORD
KeyAlias: alias/aws/ssm
Alphabet: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
Length: 30
ReturnSecret: true
ServiceToken:
!Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:secret-provider'
https://github.com/binxio/cfn-secret-provider
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Developer Workflow
Stack
TemplateDevelopers
eu-west-1
eu-west-3
Stack
Bucket
Ops
CI/CD
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Custom Rule
from typing import List
from cfnlint import CloudFormationLintRule
from cfnlint import RuleMatch, Template
class S3BucketsNotEncrypted(CloudFormationLintRule):
"""Check if S3 Bucket is not encrypted"""
id = 'E9S3BucketEncryption’
shortdesc = 'S3 Buckets must always be encrypted’
description = 'S3 Buckets should always have BucketEncryption’
def match(self, cfn: Template) -> List[RuleMatch]:
<your custom rule here>
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Custom Rule
def match(self, cfn: Template) -> List[RuleMatch]:
matches: List[RuleMatch] = []
recordsets = cfn.get_resources(['AWS::S3::Bucket’])
for name, recordset in recordsets.items():
path = ['Resources', name, 'Properties’]
full_path = ('/'.join(str(x) for x in path))
if isinstance(recordset, dict):
props = recordset.get('Properties’)
if 'BucketEncryption' not in props:
message = "Property BucketEncryption not set in {0}"
matches.append(RuleMatch(path, message.format(full_path)))
return matches
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Custom Rule
$ cfn-lint -a ../cfn-compliancy-check/rules/s3 -t badtemplate.yml
E9S3BucketEncryption Property BucketEncryption not set in Resources/S3Bucket/Properties
badtemplate.yml:4:5
E3012 Property Resources/S3Bucket/Properties/BucketName should be of type String
badtemplate.yml:5:7
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Taskcat
$ cat ci/config.yml
global:
owner: martijn@binx.io
qsname: dcv07
regions:
- eu-west-1
- eu-west-3
tests:
scenario-1:
template_file: stack.yml
parameter_input: parameters.json
$ taskcat -c ci/config.yml
... Deploying and generating reports ...
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Developer Workflow
Stack
TemplateDevelopers
eu-west-1
eu-west-3
Stack
Bucket
cfn-lint
DevOps
IAM Policies / cloud-custodian
My goals for 2019…
100+ set of custom cfn-lint rules, to
achieve a significant set of compliancy
coverage, across many AWS services
Every service or feature is supported in
CloudFormation, within 24h after the
launch
… and I need your help!
Thank you!
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Martijn van Dongen
martijn@binx.io
© 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.

More Related Content

PPTX
Containers State of the Union I AWS Dev Day 2018
PPTX
Building Global Multi-Region, Active-Active Serverless Backends I AWS Dev Day...
PDF
The Best Practices and Hard Lessons Learned of Serverless Applications
PDF
AWS CodeStar 및 Cloud9을 통한 서버리스(Serverless) 앱 개발 길잡이 - 윤석찬 (AWS 테크에반젤리스트)
PDF
"Automating AWS Infrastructure with PowerShell", Martin Beeby, AWS Dev Day Ky...
PDF
IaC: Tools of the trade
PDF
AWS Lambda 자세히 살펴보기 (조성열, AWS 시스템 엔지니어) :: AWS DevDay2018
PDF
20190223 JAWSDAYS 2019 AWS の Management Tools を使ったハイブリッドアーキテクチャ
Containers State of the Union I AWS Dev Day 2018
Building Global Multi-Region, Active-Active Serverless Backends I AWS Dev Day...
The Best Practices and Hard Lessons Learned of Serverless Applications
AWS CodeStar 및 Cloud9을 통한 서버리스(Serverless) 앱 개발 길잡이 - 윤석찬 (AWS 테크에반젤리스트)
"Automating AWS Infrastructure with PowerShell", Martin Beeby, AWS Dev Day Ky...
IaC: Tools of the trade
AWS Lambda 자세히 살펴보기 (조성열, AWS 시스템 엔지니어) :: AWS DevDay2018
20190223 JAWSDAYS 2019 AWS の Management Tools を使ったハイブリッドアーキテクチャ

Similar to CloudFormation techniques from the Dutch trenches (DVC07) - AWS re:Invent 2018 (20)

PDF
Security @ (Cloud) Scale Deep Dive
PPTX
test-sgsgsgs.pptx
PDF
DEF CON 24 - Rich Mogull - pragmatic cloud security
PPTX
Cloudformation101
PDF
Hunter Lynne - Securing AWS with Event Driven Security
PDF
Moving at the Speed-of-Cloud Without Getting Owned
PDF
Moving at the Speed-of-Cloud Without Getting Owned
PPTX
004 - Logging in the Cloud -- hide01.ir.pptx
PDF
[AWS Start-up ゼミ / DevDay 編] よくある課題を一気に解説! 御社の技術レベルがアップする 2018 秋期講習
PDF
20191023 AWS Black Belt Online Seminar Amazon EMR
PDF
AWS Training Institute in Bangalore | Best AWS Course In Bangalore
PDF
AWS CloudFormation Macros
PPTX
best aws training in bangalore
PDF
Boost your AWS Infrastructure with CDK
PDF
AWS Cloud Formation
PPTX
Göteborg Reinvent 2023_Aritra_updated.pptx
PDF
Exploring Cloud Computing with Amazon Web Services (AWS)
PDF
Safe and Fast Automation on AWS for Fun and Profit
PPTX
Cloud Formation
PDF
ITB2019 Build Fine-Grained Control of Amazon Web Services in Your CFML App - ...
Security @ (Cloud) Scale Deep Dive
test-sgsgsgs.pptx
DEF CON 24 - Rich Mogull - pragmatic cloud security
Cloudformation101
Hunter Lynne - Securing AWS with Event Driven Security
Moving at the Speed-of-Cloud Without Getting Owned
Moving at the Speed-of-Cloud Without Getting Owned
004 - Logging in the Cloud -- hide01.ir.pptx
[AWS Start-up ゼミ / DevDay 編] よくある課題を一気に解説! 御社の技術レベルがアップする 2018 秋期講習
20191023 AWS Black Belt Online Seminar Amazon EMR
AWS Training Institute in Bangalore | Best AWS Course In Bangalore
AWS CloudFormation Macros
best aws training in bangalore
Boost your AWS Infrastructure with CDK
AWS Cloud Formation
Göteborg Reinvent 2023_Aritra_updated.pptx
Exploring Cloud Computing with Amazon Web Services (AWS)
Safe and Fast Automation on AWS for Fun and Profit
Cloud Formation
ITB2019 Build Fine-Grained Control of Amazon Web Services in Your CFML App - ...
Ad

Recently uploaded (20)

PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PPTX
observCloud-Native Containerability and monitoring.pptx
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Tartificialntelligence_presentation.pptx
PPTX
Modernising the Digital Integration Hub
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Chapter 5: Probability Theory and Statistics
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
project resource management chapter-09.pdf
PDF
August Patch Tuesday
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
O2C Customer Invoices to Receipt V15A.pptx
NewMind AI Weekly Chronicles – August ’25 Week III
Univ-Connecticut-ChatGPT-Presentaion.pdf
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
observCloud-Native Containerability and monitoring.pptx
OMC Textile Division Presentation 2021.pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Tartificialntelligence_presentation.pptx
Modernising the Digital Integration Hub
A comparative study of natural language inference in Swahili using monolingua...
WOOl fibre morphology and structure.pdf for textiles
A novel scalable deep ensemble learning framework for big data classification...
NewMind AI Weekly Chronicles - August'25-Week II
Chapter 5: Probability Theory and Statistics
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Developing a website for English-speaking practice to English as a foreign la...
Module 1.ppt Iot fundamentals and Architecture
project resource management chapter-09.pdf
August Patch Tuesday
Final SEM Unit 1 for mit wpu at pune .pptx
Ad

CloudFormation techniques from the Dutch trenches (DVC07) - AWS re:Invent 2018

  • 1. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CloudFormation techniques from the Dutch trenches Martijn van Dongen Chief AWS Technology / AWS APN Ambassador Binx.io (proudly part of Xebia) D V C 0 7
  • 2. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agenda CloudFormation Custom Resources Cfn-lint Custom Rules Taskcat
  • 3. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 4. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 5. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Build if event['RequestType'] == 'Create' or event['RequestType'] == 'Update’: client = boto3.client('iam’) response = client.tag_role( RoleName=event['ResourceProperties']['RoleName’], Tags=event['ResourceProperties']['Tags’] ) cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, "NA") elif event['RequestType'] == 'Delete’: cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
  • 6. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Add IAMTaggingFunction: Type: AWS::Serverless::Function Properties: Handler: lambda.lambda_handler Timeout: 30 Role: !GetAtt 'IAMTaggingFunctionRole.Arn’ Runtime: python3.7 CodeUri: ./build/iamtagging.zip IAMTaggingFunctionRole: Type: AWS::IAM::Role ...
  • 7. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Package $ tree ├── build ├── src │ └── iamtagging │ ├── cfnresponse.py │ ├── lambda.py │ └── requirements.txt $ docker run -v $(pwd)/src:/src -v $(pwd)/build:/build binxio/python-lambda-packager:3.7
  • 8. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Use TeamRoleTags: Type: Custom::IAMTagging Properties: ServiceToken: !GetAtt IAMTaggingFunction.Arn RoleName: !Ref TeamRedRole Tags: - Key: Project Value: Alexa - Key: CostCenter Value: 382
  • 9. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Deploy $ aws cloudformation package --template-file template.yml --s3-bucket mys3bucket --output-template-file packaged.yml ... $ aws cloudformation deploy --template-file packaged.yml --capabilities CAPABILITY_IAM --stack-name iamtag
  • 10. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. 1 2 3
  • 11. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 12. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. To Production TeamRoleTags: Type: AWS::IAM::Tags Properties: ServiceToken: !GetAtt IAMTaggingFunction.Arn RoleName: !Ref TeamRedRole Tags: - Key: Project Value: Alexa - Key: CostCenter Value: 0382
  • 13. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Example Extension: Secret Provider DBPassword: Type: Custom::Secret Properties: Name: /demo/PGPASSWORD KeyAlias: alias/aws/ssm Alphabet: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 Length: 30 ReturnSecret: true ServiceToken: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:secret-provider' https://github.com/binxio/cfn-secret-provider
  • 14. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 15. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Developer Workflow Stack TemplateDevelopers eu-west-1 eu-west-3 Stack Bucket Ops CI/CD
  • 16. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 17. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 18. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Custom Rule from typing import List from cfnlint import CloudFormationLintRule from cfnlint import RuleMatch, Template class S3BucketsNotEncrypted(CloudFormationLintRule): """Check if S3 Bucket is not encrypted""" id = 'E9S3BucketEncryption’ shortdesc = 'S3 Buckets must always be encrypted’ description = 'S3 Buckets should always have BucketEncryption’ def match(self, cfn: Template) -> List[RuleMatch]: <your custom rule here>
  • 19. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Custom Rule def match(self, cfn: Template) -> List[RuleMatch]: matches: List[RuleMatch] = [] recordsets = cfn.get_resources(['AWS::S3::Bucket’]) for name, recordset in recordsets.items(): path = ['Resources', name, 'Properties’] full_path = ('/'.join(str(x) for x in path)) if isinstance(recordset, dict): props = recordset.get('Properties’) if 'BucketEncryption' not in props: message = "Property BucketEncryption not set in {0}" matches.append(RuleMatch(path, message.format(full_path))) return matches
  • 20. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Custom Rule $ cfn-lint -a ../cfn-compliancy-check/rules/s3 -t badtemplate.yml E9S3BucketEncryption Property BucketEncryption not set in Resources/S3Bucket/Properties badtemplate.yml:4:5 E3012 Property Resources/S3Bucket/Properties/BucketName should be of type String badtemplate.yml:5:7
  • 21. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  • 22. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Taskcat $ cat ci/config.yml global: owner: martijn@binx.io qsname: dcv07 regions: - eu-west-1 - eu-west-3 tests: scenario-1: template_file: stack.yml parameter_input: parameters.json $ taskcat -c ci/config.yml ... Deploying and generating reports ...
  • 23. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Developer Workflow Stack TemplateDevelopers eu-west-1 eu-west-3 Stack Bucket cfn-lint DevOps IAM Policies / cloud-custodian
  • 24. My goals for 2019…
  • 25. 100+ set of custom cfn-lint rules, to achieve a significant set of compliancy coverage, across many AWS services
  • 26. Every service or feature is supported in CloudFormation, within 24h after the launch
  • 27. … and I need your help!
  • 28. Thank you! © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved. Martijn van Dongen martijn@binx.io
  • 29. © 2018, Amazon Web Services, Inc. or its affiliates. All rights reserved.