Slide 1

Slide 1 text

AWS CDKを触ってみて NCDC Dev Meetup クラウドなんでもLT会 #6 2022/07/22 久保田 亨

Slide 2

Slide 2 text

自己紹介 氏名 : 久保田 亨 会社 : SaaS企業 職業 : インフラエンジニア 趣味 : 歩くこと

Slide 3

Slide 3 text

背景 ~2022/06 SI勤務(DC) 2022/07~(転職) SaaS企業 ・AWSサービス検証 ・AWSサービスメニュー化 ・AWSを使用 CloudFormation(CFn) CloudFormation(CFn)

Slide 4

Slide 4 text

CFn (CloudFormation) Stack Template YAML/JSON AWS Cloud CloudFormation(CFn)

Slide 5

Slide 5 text

実行環境 AWS CDK Stack Template JavaScript/TypeScript/Python/Java/C# AWS Cloud AWS CDK

Slide 6

Slide 6 text

AWS Cloud VPC Public subnet Public subnet Private subnet Private subnet AWS Cloud VPC Public subnet Public subnet Private subnet Private subnet AWS Cloud VPC Public subnet Public subnet Private subnet Private subnet AWS Cloud VPC Public subnet Public subnet Private subnet Private subnet AWS Cloud VPC Public subnet Public subnet Private subnet Private subnet

Slide 7

Slide 7 text

import { Stack, StackProps } from 'aws-cdk-lib'; import { Construct } from 'constructs'; import * as ec2 from 'aws-cdk-lib/aws-ec2'; import { Vpc } from 'aws-cdk-lib/aws-ec2'; export class VpcStack extends Stack { //別スタックから参照できるようにする public readonly vpc: Vpc; constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); const vpc_name = 'cdk-vpc'; const cidr = '10.1.0.0/16'; this.vpc = new ec2.Vpc(this, 'VPC', { vpcName: vpc_name, cidr: cidr, maxAzs: 2, subnetConfiguration: [ { cidrMask: 24, name: `${vpc_name}-public`, subnetType: ec2.SubnetType.PUBLIC, }, { cidrMask: 24, name: `${vpc_name}-private`, subnetType: ec2.SubnetType.PRIVATE_ISOLATED, }, ] }) } };

Slide 8

Slide 8 text

Resources: VPCXXXXXXX: Type: 'AWS::EC2::VPC' Properties: CidrBlock: 10.1.0.0/16 EnableDnsHostnames: true EnableDnsSupport: true InstanceTenancy: default Tags: - Key: Name Value: cdk-vpc Metadata: 'aws:cdk:path': VpcStack/VPC/Resource VPCcdkvpcpublicSubnet1SubnetYYYYYYYY: Type: 'AWS::EC2::Subnet' Properties: VpcId: !Ref VPCXXXXXXX AvailabilityZone: ap-northeast-1a CidrBlock: 10.1.0.0/24 MapPublicIpOnLaunch: true Tags: - Key: 'aws-cdk:subnet-name' Value: cdk-vpc-public - Key: 'aws-cdk:subnet-type' Value: Public - Key: Name Value: VpcStack/VPC/cdk-vpc-publicSubnet1 Metadata: 'aws:cdk:path': VpcStack/VPC/cdk-vpc- publicSubnet1/Subnet VPCcdkvpcpublicSubnet1RouteTableZZZZZZZZ: Type: 'AWS::EC2::RouteTable' Properties: VpcId: !Ref VPCXXXXXXXX Tags: - Key: Name Value: VpcStack/VPC/cdk-vpc-publicSubnet1 ・・・・222行(CDKで出力されたテンプレート)

Slide 9

Slide 9 text

https://qiita.com/Toru_Kubota/items/f6fb42c5da442b03a98f ALB+ECS+Aurora

Slide 10

Slide 10 text

//aws-ecs-patternsモジュール使用 new ecsp.ApplicationLoadBalancedFargateService(this, 'WebApp01', { cluster, domainName: domain_name, domainZone, memoryLimitMiB: 512, desiredCount: 2, cpu: 256, assignPublicIp: true, loadBalancerName: 'WebApp01-lb01', publicLoadBalancer: true, taskImageOptions: { image: ecs.ContainerImage.fromRegistry('nginx'), },}); ALB+Fargate設定(一部抜粋)

Slide 11

Slide 11 text

・セキュアなベースラインを提供するテンプレート ・AWS CDKで実装 ・共通設定とシステム固有設定の2層 Baseline Environment on AWS

Slide 12

Slide 12 text

共通設定箇所 Amazon GuardDuty AWS Security Hub AWS CloudTrail AWS Config Amazon SNS AWS Systems Manager

Slide 13

Slide 13 text

・少ないコード量で運用が楽そう! ・書き方は慣れれば難しくない! ・BLEAと合わせて運用が楽になりそう! AWS CDKを触ってみて