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

DMM 決済基盤で AWS CDK を使っている話

DMM 決済基盤で AWS CDK を使っている話

CDK meetup #2 @onlineで発表したスライドです。

HukurouKk

March 03, 2020
Tweet

Other Decks in Programming

Transcript

  1. ։ൃํ਑ w ͋Δ۠෼ͰTUBDLΛ෼͚Δ.VMUJ4UBDLӡ༻ QSPEVDU MPHج൫  .PDL"QJ &$3 71$ͳͲ 

    w υϝΠϯͷূ໌ॻऔಘ "$. ͳͲೋ౓໨ʹ΍Δ͜ͱ͸ͳ͍෦෼͸ 8FC6*Ͱߦͳ͍ͬͯΔɻ w ؀ڥͷ੾Γସ͑͸DELEFQMPZDFOWEFWͷΑ͏ͳDPOUFYUʹ౉͠ ͯ੾Γସ͍͑ͯ͠Δɻ const envName = app.node.tryGetContext('env') || 'dev'; const config = app.node.tryGetContext('environments')[envName];
  2. ศརͳ$POTUSVDU-JCSBSZ w "84$%,ʹ͸$POTUSVDUMJCSBSZͱ͍͏$MPVE'PSNBUJPOͰ هࡌ͢Δ಺༰ΛΧϓηϧԽ͞ΕͨϞδϡʔϧ͕͋Δɻ w $POTUSVDUʹ΋छྨ͕͋Γɺ-PX-FWFM$POTUSVDU )JHI -FWFM$POTUSVDU 1BUUFSOTͷࡾछྨ͕͋ΓɺͦΕͧΕఆٛϨ ϕϧ͕ҧ͏΋ͷ͕༻ҙ͞Ε͍ͯΔɻ

    w ݸਓతʹ͸)JHI-FWFM$POTUSVDUɺ1BUUFSOT͕͋Ε͹$%, ߏங͢ΔϝϦοτ͕ग़͖ͯͦ͏͔ͳͱࢥ͍ͬͯ·͢ɻ ࢀߟ AWS Cloud Development Kit (AWS CDK) Developer Guide https://docs.aws.amazon.com/cdk/latest/guide/constructs.html
  3. const subnets = vpc.selectSubnets({ subnetGroupName: isolatedSubnetName }); const redisSubnetGroup =

    new elasticache.CfnSubnetGroup(this, `${id} RedisClusterPrivateSubnetGroup`, { cacheSubnetGroupName: `${env}ElastiCacheSubnetGroup`, subnetIds: subnets.subnetIds, description: `${env} ElastiCache SubnetGroup` }); const redisReplication = new elasticache.CfnReplicationGroup(this, `${id} RedisReplicaGroup`, { engine: ‘redis’, cacheNodeType: config.cacheNodeType, replicasPerNodeGroup: 1, numNodeGroups: 1, automaticFailoverEnabled: true, autoMinorVersionUpgrade: true, replicationGroupDescription: ‘cluster redis’, cacheSubnetGroupName: redisSubnetGroup.cacheSubnetGroupName, securityGroupIds: [elasticacheSG.securityGroupId] }); redisReplication.addDependsOn(redisSubnetGroup); -PX-FWFM$POTUSVDU4BNQMF FMBTUJDBDIF
  4. )JHI-FWFM$POTUSVDUTBNQMF "1*HBUFXBZ-BNCEB export class LambdaApigatewayStackStack extends cdk.Stack { constructor(scope: cdk.Construct,

    id: string, props?: cdk.StackProps) { super(scope, id, props); const restApi = new RestApi(this, id, { restApiName: 'SampleApiGateway', }); const sampleResource = restApi.root.addResource('SampleResource'); const sanpelFun = new Function(this, 'MyFunction', { runtime: Runtime.NODEJS_12_X, handler: 'index.handler', code: new AssetCode('./src/lambda'), }); const confirmDeletionIntegration = new LambdaIntegration(sanpelFun); sampleResource.addMethod('POST', confirmDeletionIntegration); } }
  5. export class EcsPatternSampleStack extends Stack { constructor(scope: Construct, id: string,

    props?: StackProps) { super(scope, id, props); const cluster = new Cluster(this, 'EcsPatternSampleCluster', { clusterName: 'EcsPatternSampleCluster', }); const taskDefinition = new FargateTaskDefinition(this, 'TaskDefinition'); const container = taskDefinition.addContainer('EcsPatternSampleContainer', { image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample') }); container.addPortMappings({ containerPort: 80 }); new ApplicationLoadBalancedFargateService(this, 'EcsPatternSampleService', { cluster: cluster, memoryLimitMiB: 1024, cpu: 512, desiredCount: 1, taskDefinition: taskDefinition }); } } 1BUUFSOTTBNQMF FDTQBUUFSOT
  6. ࢀߟ BXTDELSFGFSFODFBXTTUFQGVODUJPOUBTLT IUUQTEPDTBXTBNB[PODPNDELBQJMBUFTUEPDTBXTTUFQGVODUJPOTUBTLTSFBENFIUNM const firstTask = new sfn.Task(stack, `${stack.stackName}_CommitTask_${serviceName}`, {

    task: new sfnTask.InvokeFunction(stepFunc) }).addRetry({ errors: failErrors, maxAttempts: 0, }).addRetry({ errors: retryErrors, interval: Duration.seconds(10), maxAttempts: 26, backoffRate: 1.3, }).addCatch(fail, { errors: failErrors }).addCatch(secondTask, { errors: retryErrors }); $POTUSVDUͷNFUIPEͰUBTLΛ৭ʑઃఆͰ͖Δ
  7. ├── README.md ├── bin │ └── credit-gateway.ts ├── cdk.json ├──

    lib │ ├── credit-gateway-log-stack.ts │ ├── credit-gateway-stack.ts │ ├── schema │ │ └── credit-gateway-schema.ts │ └── util │ └── wafacl.ts ├── package-lock.json ├── package.json ├── src │ └── lambda │ ├── common │ ├── confirm-deletion │ ├── delete │ └── layer ├── test │ └── src │ └── lambda └── tsconfig.json