Slide 1

Slide 1 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with 2 0 - 2 2 . 1 0 . 2 0 2 0

Slide 2

Slide 2 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with CDK @hixi-hyi F - 9

Slide 3

Slide 3 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with T?R/ E<=2 @hixi-hyi 2013@HB1P-,#,-G93P -&+&( %-'-$!+" :JI0 &),(!- SY N;P4KF+"WX C> 7J6A5ODV+*,- ,+%(7JM8. Cloudformation 5O CDK ))-L CDK QU

Slide 4

Slide 4 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with ,! 4#% • 3$ (-)4 • "02! .6517*/ • !#%8. ! +'!&

Slide 5

Slide 5 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with CDK • id •

Slide 6

Slide 6 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 7

Slide 7 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with cdk init cdk init app --language=typescript aws-cdk-bestpractice

Slide 8

Slide 8 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with cdk init cdk init app --language=typescript aws-cdk-bestpractice bin/aws-cdk-bestpractice.ts const app = new cdk.App(); new AwsCdkBestpracticeStack(app, 'AwsCdkBestpracticeStack’);

Slide 9

Slide 9 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with cdk init cdk init app --language=typescript aws-cdk-bestpractice bin/aws-cdk-bestpractice.ts const app = new cdk.App(); new AwsCdkBestpracticeStack(app, 'AwsCdkBestpracticeStack’); lib/aws-cdk-bestpractice.ts export class AwsCdkBestpracticeStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, …) { super(scope, id, props); } }

Slide 10

Slide 10 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with cdk init cdk init app --language=typescript aws-cdk-bestpractice bin/aws-cdk-bestpractice.ts const app = new cdk.App(); new AwsCdkBestpracticeStack(app, 'AwsCdkBestpracticeStack’); lib/aws-cdk-bestpractice.ts export class AwsCdkBestpracticeStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, …) { super(scope, id, props); } }

Slide 11

Slide 11 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with ! • VOHN%2T/(0&'*+%AS VOHN,.-0)%1 U4" • /(0&ASW"PB human readable ;9% /(0&K F?5%JD construct 37MCE$#" IU K" "LX /(0&F?8R@= "#%1 6G "Q:

Slide 12

Slide 12 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with id - const id = new cdkid.Identifier({ section: resolveEnvironmentFromAwsAccountId(), }); const app = new cdk.App(); id.child({legion: "product"}).scope((id: cdkid.Identifier) => { id.child({cohort: "service"}).scope((id: cdkid.Identifier) => { new stack.ProductServiceApi(app, id.child({family: 'api'})); }); }); export class ProductServiceApi extends cdk.Stack { constructor(app: cdk.App, id: cdkid.Identifier, props: ProductServiceApiProps) { ... } } https://github.com/hixi-hyi/aws-cdk-identifier

Slide 13

Slide 13 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with id - export class ProductServiceApi extends cdk.Stack { constructor(app: cdk.App, id: cdkid.Identifier, props: ProductServiceApiProps) { super(app, id.stackName, props); const fargate = new construct.Fargate(this, id.child("Aurora"), { maxCapacity: cdkid.Variables.resolve(id, cdkid.RankLoc.Section, { dev: 1, prod: 10, }), }); } https://github.com/hixi-hyi/aws-cdk-identifier

Slide 14

Slide 14 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with id - export class Fargate extends cdk.Construct { constructor(app: cdk.Construct, id: cdkid.Identifier, props: FargateProps) { super(app, id.constructName); const cluster = new ecs.Cluster(this, 'Cluster’, { clusterName: id.camelName, ... }); ... } https://github.com/hixi-hyi/aws-cdk-identifier Construct

Slide 15

Slide 15 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with id - +α const patterns = new ecsPatterns.ApplicationLoadBalancedFargateService(this, “Service”, { ... taskImageOptions: { environment: { ‘IAC_CORE_SECTION’: id.rank.section, // dev or prod }, }, }); https://github.com/hixi-hyi/aws-cdk-identifier

Slide 16

Slide 16 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with id

Slide 17

Slide 17 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 18

Slide 18 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with • #!"$ • !

Slide 19

Slide 19 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with &/) • 7' 13(4%-.8 • *0#2 $,13( !"56 • • +

Slide 20

Slide 20 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with ├── bin │ └── infra.ts └── lib ├── @aws-cdk/ ├── construct/ ├── helper/ └── stack/

Slide 21

Slide 21 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with ├── bin │ └── infra.ts (lib/stack stack ! "+) └── lib ├── @aws-cdk (cdk % )) ├── construct (,) L2/patterns construct "+) ├── helper (('* $ "+) └── stack (lib/construct ! "+)

Slide 22

Slide 22 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 23

Slide 23 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with bin/infra.ts id = cdkid.Identifier({ section: resolveEnvironmentFromAwsAccountId() }); const common = new stack.ProductCommon(app, id); new stack.ProductServiceApi(app, id.child({cohort: “service”, family: 'api'}), { common });

Slide 24

Slide 24 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 25

Slide 25 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with lib/stack/* export class ProductServiceApi extends cdk.Stack { constructor(app: cdk.App, id: cdkid.Identifier, props: ProductServiceApiProps) { super(app, id.stackName, props); }

Slide 26

Slide 26 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with lib/stack/* export class ProductServiceApi extends cdk.Stack { constructor(app: cdk.App, id: cdkid.Identifier, props: ProductServiceApiProps) { super(app, id.stackName, props); const ecr = new construct.Ecr(this, id.child('Repository’)); }

Slide 27

Slide 27 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with lib/stack/* export class ProductServiceApi extends cdk.Stack { constructor(app: cdk.App, id: cdkid.Identifier, props: ProductServiceApiProps) { super(app, id.stackName, props); const ecr = new construct.Ecr(this, id.child('Repository’)); const fargate = new construct.FargateL7Webapp(this, id.child('Webapp'), { ... image: ecs.ContainerImage.fromEcrRepository(ecr.repository), maxCapacity: cdkid.Variables.resolve(id, cdkid.RankLoc.Section, { dev : 1, prod: 10, }), }); ... }

Slide 28

Slide 28 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with lib/stack/* export class ProductServiceApi extends cdk.Stack { constructor(app: cdk.App, id: cdkid.Identifier, props: ProductServiceApiProps) { super(app, id.stackName, props); const ecr = new construct.Ecr(this, id.child('Repository’)); const fargate = new construct.FargateL7Webapp(this, id.child('Webapp'), { ... image: ecs.ContainerImage.fromEcrRepository(ecr.repository), maxCapacity: cdkid.Variables.resolve(id, cdkid.RankLoc.Section, { dev : 1, prod: 10, }), }); ... }

Slide 29

Slide 29 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 30

Slide 30 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with lib/construct/*

Slide 31

Slide 31 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 32

Slide 32 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with lib/@aws-cdk/* https://github.com/aws/aws-cdk/issues/9926 https://github.com/aws/aws-cdk/pull/10324

Slide 33

Slide 33 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 34

Slide 34 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with lib/helper/* export function LogGroupRetentionDay(id: cdkid.Identifier): logs.RetentionDays { return cdkid.Variables.resolve(id, cdkid.RankLoc.Section, { dev: logs.RetentionDays.TWO_WEEKS, prod: logs.RetentionDays.INFINITE, }) }

Slide 35

Slide 35 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with *'&1 ├── bin │ └── infra.ts (lib/stack ! stack $ %/) └── lib ├── @aws-cdk (cdk #) -) ├── construct (0- L2/patterns construct %/) ├── helper (,"+.#( %/) └── stack (lib/construct ! $ %/)

Slide 36

Slide 36 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 37

Slide 37 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with • id )-$ • )&%",# (' )&* ! + https://github.com/hixi-hyi/aws-cdk-bestpractice

Slide 38

Slide 38 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 39

Slide 39 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 40

Slide 40 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with Q1. L1 L2 L2

Slide 41

Slide 41 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with Q1. L1 + L2 + *%&"$ # )!' lib/@aws-cdk ( PR

Slide 42

Slide 42 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 43

Slide 43 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with Q2.

Slide 44

Slide 44 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with Q1. cdk diff

Slide 45

Slide 45 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with

Slide 46

Slide 46 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with Q3. IaC ,9 814)*)+3 !%02&'7 • 81-%8145/ IAM Policy .' • SSM Parameters /service/xxx/app/* #"8145/6$( • !81 Dockerfile

Slide 47

Slide 47 text

Thank you! © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. In Partnership with CDK • id • https://github.com/hixi-hyi/aws-cdk-bestpractice