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

Perl MongersのためのAWS_CDK入門

karupanerura
February 19, 2021
90

Perl MongersのためのAWS_CDK入門

Japan.pm 2021

karupanerura

February 19, 2021
Tweet

Transcript

  1. @karupanerura • ୅දཧࣄ @ Japan Perl Association • ΤϯδχΞ @

    DeNA, Co,. LTD. • Perl/Go/Type Script/Java/etc… • PAUSE: KARUPA
  2. AWS Cloud Development Kit • ΞϓϦέʔγϣϯΫϥ΢υϦιʔεΛఆٛ͢ΔϑϨʔϜϫʔΫ • TypeScript, JavaScript, Python,

    Java, C# Ͱ࢖͑Δ • TypeScript͔Β֤ݴޠʹτϥϯεύΠϧ͞Ε͍ͯΔҝ • AWS CloudFormationΛ࢖ͬͯϓϩϏδϣχϯά͢Δ
  3. cdk init app --language=typescript . !"" README.md !"" bin #

    %"" foo.ts !"" cdk.json !"" jest.config.js !"" lib # %"" foo-stack.ts !"" package-lock.json !"" package.json !"" test # %"" foo.test.ts %"" tsconfig.json 3 directories, 9 files
  4. . !"" README.md !"" bin # %"" foo.ts !"" cdk.json

    !"" jest.config.js !"" lib # %"" foo-stack.ts !"" package-lock.json !"" package.json !"" test # %"" foo.test.ts %"" tsconfig.json 3 directories, 9 files ࣮ߦͷى఺ Stackͷఆٛ cdk init app --language=typescript
  5. import * as cdk from '@aws-cdk/core'; export class ${Project}Stack extends

    cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); // The code that defines your stack goes here } } lib/${project}-stack.ts
  6. import * as cdk from '@aws-cdk/core'; import * as s3

    from '@aws-cdk/aws-s3'; export class FooStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); new s3.Bucket(this, "SampleBucket", { encryption: s3.BucketEncryption.S3_MANAGED, bucketName: 'japan-pm-2021-sample-bucket', publicReadAccess: true, websiteIndexDocument: 'index.html', accessControl: s3.BucketAccessControl.PUBLIC_READ, }) } } lib/${project}-stack.ts
  7. import * as cdk from '@aws-cdk/core'; import * as s3

    from '@aws-cdk/aws-s3'; export class FooStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); new s3.Bucket(this, "SampleBucket", { encryption: s3.BucketEncryption.S3_MANAGED, bucketName: 'japan-pm-2021-sample-bucket', publicReadAccess: true, websiteIndexDocument: 'index.html', accessControl: s3.BucketAccessControl.PUBLIC_READ, }) } } lib/${project}-stack.ts FooStackͷείʔϓͰ࡞੒
  8. import * as cdk from '@aws-cdk/core'; import * as s3

    from '@aws-cdk/aws-s3'; export class FooStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); new s3.Bucket(this, "SampleBucket", { encryption: s3.BucketEncryption.S3_MANAGED, bucketName: 'japan-pm-2021-sample-bucket', publicReadAccess: true, websiteIndexDocument: 'index.html', accessControl: s3.BucketAccessControl.PUBLIC_READ, }) } } lib/${project}-stack.ts SampleBucketͬͯIDͰѻ͏
  9. import * as cdk from '@aws-cdk/core'; import * as s3

    from '@aws-cdk/aws-s3'; export class FooStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); new s3.Bucket(this, "SampleBucket", { encryption: s3.BucketEncryption.S3_MANAGED, bucketName: 'japan-pm-2021-sample-bucket', publicReadAccess: true, websiteIndexDocument: 'index.html', accessControl: s3.BucketAccessControl.PUBLIC_READ, }) } } lib/${project}-stack.ts ͲͷΑ͏ͳ΋ͷ͔ৄࡉΛࢦఆ
  10. npm run cdk -- bootstrap • CDK toolkit stackΛAWS্ʹ࡞੒͢Δ •

    cdk͕ಈ࡞͢ΔͨΊʹඞཁͳϦιʔεΛ࡞੒ • ར༻͢ΔϦʔδϣϯຖʹ࠷௿1౓͸࣮ߦ͢Δඞཁ͕͋Δ • ॳΊͯར༻͢Δ৔߹͸·࣮ͣߦ͢Δඞཁ͕͋Δ
  11. npm run cdk -- deploy FooStack • FooStackΛϓϩϏδϣχϯά͢Δ • FooStackΛCloudFormation্ʹ࡞੒͢Δ

    • FooStackͷঢ়ଶͱࠩ෼ΛऔΓɺࠩ෼ΛϓϩϏδϣχϯά͢Δ • ੒ޭͨ͠ΒFooStackͷঢ়ଶΛ࠷৽ͷঢ়ଶʹߋ৽͢Δ
  12. cdk.out • cdk deployͷࡍʹStackͷCfn TemplateΛ͜͜ʹੜ੒͢Δ • cdk synth $Stack Ͱੜ੒͚ͩ͢Δ͜ͱ΋Ͱ͖Δ

    • ࣮ࡍͷCfn TemplateͱίʔυΛಡΈൺ΂ͯཧղΛਂΊΔ • Construct͕ͳʹΛந৅Խ͍ͯ͠Δͷ͔ཧղ͢Δͷʹ໾ཱͭ