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

AWS CDKを触ってみて

AWS CDKを触ってみて

Toru_Kubota

July 22, 2022
Tweet

More Decks by Toru_Kubota

Other Decks in Technology

Transcript

  1. 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
  2. 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, }, ] }) } };
  3. 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で出力されたテンプレート)
  4. //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設定(一部抜粋)