Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Authoring CloudFormation Templates with Cloud9,...

Authoring CloudFormation Templates with Cloud9, Boto3 and Troposphere

You can use CloudFormation to deploy a Cloud9 Environment with an integrated CodeCommit repository. In this demo, we'll also show how to create, run, and debug Python files, AWS SDK APIs (with Boto3), and use Troposphere to generate a CloudFormation YAML template.

Luis Colon @ AWS

March 21, 2018
Tweet

More Decks by Luis Colon @ AWS

Other Decks in Programming

Transcript

  1. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Luis Colon (@luiscolon1) Sr.Developer Advocate, CloudFormation Wed 03.21.2018 Authoring CloudFormation Templates with Cloud9, CodeCommit, Boto3 and Troposphere Meetup: Seattle AWS Architects and Engineers
  2. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. About Me Luis Colon [email protected] ; @luiscolon1 Sr. Dev Advocate, AWS CloudFormation 1.5 years at AWS Previously: Chief Architect / DevOps SDM at TeamQuest Director of R&D, Publishing Company Software Engineering & Data Science, 25+ yrs in tech
  3. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. About You? Active AWS Users? More than 2 years of AWS Experience? CloudFormation Users?
  4. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Agenda CloudFormation 101 About Cloud9 Building a Cloud9 Environment with CloudFormation Editing Files & Running Programs Building CloudFormation templates in Cloud9
  5. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. CloudFormation 101 Over 350,000 customers use AWS CloudFormation Over 75% of the top 10k highest spend AWS customers Over 2.4 million AWS CloudFormation stacks managed Code in YAML or JSON directly or use sample templates Upload local files or from an S3 bucket Create stack using console, API or CLI Stacks and resources are provisioned
  6. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Infrastructure as Code CDN AppServer Database S3 Multi-tier Transactional (Java, LAMP) Cache Containers NoSQL Orchestrate Microservices Transactional (Docker, k8s) Endpoints Step Fn’s IoT Functions Serverless Transactional (Lambda, APIs, IoT) Streams Spark Warehouse ETL Big Data Analytical (Data Lakes, Hubs) …
  7. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Best Practices Consumer website, seller website, mobile backend Search engine, payment gateway, review engine, recommendations CRM database, common monitoring tools, other stateful resources, alarms VPCs, NAT gateways, VPNs, subnets, security groups, load balancers IAM users, groups, roles, policies Frontend Services Backend Services Shared Services Base Network Identity & Access Dev Integ Stage Prod 1 2 Break stacks by layers and lifecycle Reuse stacks by environments
  8. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. CloudFormation 101 About Cloud9 Building a Cloud9 Environment with CloudFormation Editing Files & Running Programs Building CloudFormation templates in Cloud9
  9. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Cloud9 IDE • Browser-based • Tablets • Chromebooks • Ace Editor • Previously: Mozilla Bespin / Skywriter
  10. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Cloud9 IDE • Syntax highlighting • Live collaboration • Debugging • Command line • EC2 backed
  11. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. CloudFormation 101 About Cloud9 Building a Cloud9 Environment with CloudFormation Editing Files & Running Programs Building CloudFormation templates in Cloud9
  12. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Building a Cloud9 Environment with CloudFormation • Start by adding the Cloud9 environment resource • Specify EC2 instance type • Make a CodeCommit repo • Automatically integrated • AWS CLI pre-configured • Python 2 & 3, Node 6 • Prerequisites: • EC2 instance needs a subnet • IAM user must belong to a group with AWSCodeCommitPowerUser and AWSCodeCommitFullAccess policies • Cloud9 is available now in N. Virginia, Ohio, Oregon, Ireland, and Singapore regions
  13. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Building a Cloud9 Environment with CloudFormation AWSTemplateFormatVersion: "2010-09-09"
 Description: A CodeCommit Repo and Cloud9 Dev Environment
 Resources:
 MyRepo:
 Type: "AWS::CodeCommit::Repository"
 Properties:
 RepositoryName: MyRepo
 RepositoryDescription: Sample Repo for Cloud9 Demo
 MyC9Environment:
 Type: "AWS::Cloud9::EnvironmentEC2"
 Properties:
 Repositories:
 - PathComponent: /cfn
 RepositoryUrl: !GetAtt MyRepo.CloneUrlHttp
 InstanceType: t2.micro
  14. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. CloudFormation 101 About Cloud9 Building a Cloud9 Environment with CloudFormation Editing Files & Running Programs Building CloudFormation templates in Cloud9
  15. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Demo 2 README.md & sample.py
  16. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. CloudFormation 101 About Cloud9 Building a Cloud9 Environment with CloudFormation Editing Files & Running Programs Building CloudFormation templates in Cloud9
  17. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. AWS SDK • One of the three primary ways to operate in AWS • Boto3 is the Python SDK for AWS • Console, CLI and APIs • Demo: creating S3 buckets with Python and Boto3
  18. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. CloudFormation Authoring • Traditionally: JSON • Most other tools and environments can/still use it • YAML • More human-readable, compact • SDK/API with higher-level language • Python, Ruby, TypeScript, …
  19. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Troposphere • Generate CloudFormation Templates from Python • Mature project on Github • Generate YAML and JSON • Demo: generate a template creating 3 EC2 instances with a for loop in Python
  20. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Demo 3 AWS SDK, Boto3 and Troposphere
  21. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. CloudFormation 101 About Cloud9 Building a Cloud9 Environment with CloudFormation Editing Files & Running Programs Building CloudFormation templates in Cloud9
  22. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Final Thoughts • Cloud9 storage defaults to 8GB • Check blog post at http://amzn.to/2FIzsNs for step by step instructions on how to expand it • Keep your templates versioned • Treat them as code. Really. • Keep them small, reusable, and test them • Validation Pipeline: http://amzn.to/2hrz8rM • see next slide
  23. © 2018, Amazon Web Services, Inc. or its Affiliates. All

    rights reserved. Thx :) Luis Colon (@luiscolon1 on Twitter & [email protected]) Sr.Developer Advocate, CloudFormation Wed 03.21.2018