Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Perl MongersのためのAWS_CDK入門
Search
karupanerura
February 19, 2021
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Perl MongersのためのAWS_CDK入門
Japan.pm 2021
karupanerura
February 19, 2021
More Decks by karupanerura
See All by karupanerura
音を出したい
karupanerura
0
160
Perl Meets \w+ あるいは開発を支えるPerl活用の実例集
karupanerura
0
110
log
karupanerura
1
130
Use Perl as Better Shell Script
karupanerura
0
990
GoでParserを書く
karupanerura
4
1.1k
マイ隙間家具OSSたちのご紹介
karupanerura
2
320
Mustache Template 話 2024
karupanerura
0
86
1つの言語を原点に色々な言語を学ぶということ
karupanerura
4
4.6k
Javaの実装をPerlでテストする
karupanerura
0
1.5k
Featured
See All Featured
Designing for Performance
lara
612
70k
Code Review Best Practice
trishagee
74
20k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
490
Marketing to machines
jonoalderson
1
5.9k
How to make the Groovebox
asonas
2
2.5k
Ruling the World: When Life Gets Gamed
codingconduct
0
430
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
620
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
47k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
800
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Transcript
(?:Perl MongersͷͨΊͷ)? AWS CDKೖ Japan.pm 2021 id:karupanerura
@karupanerura • දཧࣄ @ Japan Perl Association • ΤϯδχΞ @
DeNA, Co,. LTD. • Perl/Go/Type Script/Java/etc… • PAUSE: KARUPA
ͳ͢͜ͱ • AWS CDKͱͦͷΈ • AWS CDKͷֶͼํ • AWS CDKͷצॴ
• ·ͱΊ
AWS CDKͱͦͷΈ
AWS CDK #ͱ
AWS Cloud Development Kit https://aws.amazon.com/jp/cdk/
AWS Cloud Development Kit • ΞϓϦέʔγϣϯΫϥυϦιʔεΛఆٛ͢ΔϑϨʔϜϫʔΫ • TypeScript, JavaScript, Python,
Java, C# Ͱ͑Δ • TypeScript͔Β֤ݴޠʹτϥϯεύΠϧ͞Ε͍ͯΔҝ • AWS CloudFormationΛͬͯϓϩϏδϣχϯά͢Δ
AWS CloudFormation?
AWS CloudFormation (Cfn) https://aws.amazon.com/jp/cloudformation/
AWS CloudFormation (Cfn) • ܾΊΒΕͨܗࣜͷYAML(ςϯϓϨʔτ)ͰAWSϦιʔεΛఆٛ • ͦΕΛ࣮ࡍͷϦιʔεͱͯ͠ϓϩϏδϣχϯά • Ϧιʔεͷঢ়ଶΛAWS্ʹอ࣋͢Δ •
มߋͦͷ͚ࠩͩΛө
ͭ·Γ
AWS CDK͜͏ಈ͘ "84$%, "84 $MPVE'PSNBUJPO "843FTPVSDFT ςϯϓϨʔτੜ ϓϩϏδϣχϯά
AWS CDK AWS CloudFormationͷςϯϓϨʔτΛ ಈతʹੜ͢Δଠ
ςϯϓϨʔτΤϯδϯ͡ΌΜ
ʢͪΐͬͱҧ͍·͢ʣ
ͳʹ͕ҧ͏ͷ͔
ςΩετͷϨϕϧͰ ͋Ε͜ΕΔΘ͚Ͱͳ͍
AWS CDKͷಛ • ίʔυͰநతʹϦιʔεͦͷґଘؔͳͲΛදݱ͢Δ • ConstructͱStackͱ͍͏֓೦Λ༻͍Δ • Construct: ࣮ࡍʹߏ͢ΔϦιʔε܈ͷநදݱ •
Stack: ϓϩϏδϣχϯά͢Δ୯Ґͷදݱ
ͭ·ΓͲ͏͍͏͜ͱͳͷ͔
࣮ࡍͷߏྫ
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
. !"" 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
bin/${project}.ts • ࣮ߦͷىͱͳΔϑΝΠϧ • StackΦϒδΣΫτΛ࡞͢Δ • ͜ΕʹΑͬͯStackͷIDΛCDK͕ೝࣝͰ͖ΔΑ͏ʹͳΔ • ίϯετϥΫλʹύϥϝʔλΛ͢͜ͱͰ͖Δ
lib/${project}-stack.ts • StackͷఆٛΛ͢Δ • ͜ͷStackͰͲͷConstructΛߏ͢Δͷ͔Λදݱ͢Δ • StackͷίϯετϥΫλ͔Βߏ͢ΔConstructͷΠϯελϯε Λੜ͢Δ
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
ConstructΛ࡞͍ͬͯͳ͍ ۭͷStackʹͳ͍ͬͯΔ
ެࣜʹఏڙ͞Ε͍ͯΔConstructΛՃ
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
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ͷείʔϓͰ࡞
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Ͱѻ͏
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 ͲͷΑ͏ͳͷ͔ৄࡉΛࢦఆ
࣮ࡍʹ࡞ͬͯΈΔ (DEMO) http://japan-pm-2021-sample-bucket.s3-website-ap-northeast-1.amazonaws.com/
ͳʹΛͨ͠ͷ͔
npm run cdk -- bootstrap • CDK toolkit stackΛAWS্ʹ࡞͢Δ •
cdk͕ಈ࡞͢ΔͨΊʹඞཁͳϦιʔεΛ࡞ • ར༻͢ΔϦʔδϣϯຖʹ࠷1࣮ߦ͢Δඞཁ͕͋Δ • ॳΊͯར༻͢Δ߹·࣮ͣߦ͢Δඞཁ͕͋Δ
npm run cdk -- deploy FooStack • FooStackΛϓϩϏδϣχϯά͢Δ • FooStackΛCloudFormation্ʹ࡞͢Δ
• FooStackͷঢ়ଶͱࠩΛऔΓɺࠩΛϓϩϏδϣχϯά͢Δ • ޭͨ͠ΒFooStackͷঢ়ଶΛ࠷৽ͷঢ়ଶʹߋ৽͢Δ
ͭ·Γ
ConstructͱͳΜͩͬͨͷ͔ • ConstructʮΫϥυίϯϙʔωϯτʯΛදݱ͢Δ֓೦ • جຊ s3.Bucket ͳͲެࣜʹఏڙ͞Ε͍ͯΔͷΛ͏ • ෦తʹෳͷϦιʔεΛ࡞͍ͬͯΔͷ͋Δ •
நConstructʹΑͬͯҟͳΔ
ConstructͱͳΜͩͬͨͷ͔ • ࠷ந͕͍ConstructCfnͷදݱͱ΄ͱΜͲಉ͡ • ͨͱ͑ s3.CfnBucket ͳͲ͕ଘࡏ͢Δ • શͯͷConstruct࠷ऴతʹCfnͷConstructΛߏ͢Δ
StackͱͳΜͩͬͨͷ͔ • AWS CDK (Cfn) ʹ͓͚ΔσϓϩΠͷ୯Ґ • 1ͭͷStack1ͭͷ୯ҐͰϓϩϏδϣχϯά͞ΕΔ • ҙͷͷStackΛఆٛ͢Δ͜ͱ͕Ͱ͖Δ
• StackؒͰConstructʹґଘؔΛͨͤΔ͜ͱͰ͖Δ
AWS CDKͷֶͼํ
AWS CDKͷֶशϦιʔε • ެࣜυΩϡϝϯτ • https://docs.aws.amazon.com/cdk/latest/guide/ getting_started.html • CDK Workshop
• https://cdkworkshop.com/
ެࣜυΩϡϝϯτ • ࠷৴པͰ͖Δ༰͕ࡌ͍ͬͯΔʢͣʣ • Concepts ʹͦΕͧΕͷཁૉͷ֓೦͕ࡌ͍ͬͯΔ • StackConstructͳͲͷ֓೦͜͜ΛಡΊཧղͰ͖Δ • ΄͔ʹ৭ʑͳͷ͕͋Δ
CDK Workshop • CDKΛ࣮ࡍʹͬͯΈΔνϡʔτϦΞϧ • खݩͰίϚϯυίʔυΛ࣮ࡍʹଧͬͨΓॻ͍ͨΓͯ͠ࢼ͢ • ͻͱͱ͓ΓͷࣄΛ͞ΒͬͱֶͿ͜ͱ͕Ͱ͖Δ • ࣮ࡍʹCDKΛ৽نʹͬͯΈΔ໘Ͱྑ͍ڭࡐͱͳΔ
ͦͷଞ
AWS Construct library • AWS͕ެࣜʹఏڙ͢ΔجૅతͳConstructू • https://docs.aws.amazon.com/cdk/api/latest/docs/aws-construct-library.html • ΄ͱΜͲͷαʔϏε͕ཏ͞Ε͍ͯΔ •
جຊతʹ͜ΕΛͬͯߏ͢Δ • நͷʹΑ༷ͬͯʑͳͷͰΑ͘આ໌ΛಡΉඞཁ͕͋Δ
AWS Solutions Constructs • AWS͕ެࣜʹఏڙ͢ΔఆܗύλʔϯͷConstructू • https://aws.amazon.com/jp/solutions/constructs/patterns/ • Α͘͏AWS ResourceͷΈ߹ΘͤΛఏڙ
• ͦΕͳΓʹந͕ߴ͍ͷ͕ଟ͍ • S3ͱLambdaͷηοτͳͲ
cdk.out • cdk deployͷࡍʹStackͷCfn TemplateΛ͜͜ʹੜ͢Δ • cdk synth $Stack Ͱੜ͚ͩ͢Δ͜ͱͰ͖Δ
• ࣮ࡍͷCfn TemplateͱίʔυΛಡΈൺͯཧղΛਂΊΔ • Construct͕ͳʹΛநԽ͍ͯ͠Δͷ͔ཧղ͢Δͷʹཱͭ
AWS CDKͷצॴ
KANDOKORO • CloudFormationͷཧղ • Constructͷந • Stackͷڥք • ςετ
CloudFormation NO RIKAI • ࠷ऴతʹCloudFormationʹߦ͖ண͘ • ͲΜͳτϥϒϧCloudFormationͷTemplateΛಡΊ͔Δ • CloudFormationΛखܰʹѻ͏ͨΊͷCDKͱ͍͏ؾ࣋ͪͩͱָ •
CloudFormationͰग़དྷͳ͍͜ͱग़དྷͳ͍
Constructͷநʹҙ͢Δ • AWS Construct library༷ʑͳநͷConstructΛఏڙ • Γ͍ͨࣄίϯτϩʔϧ͍ͨ͠ϨϕϧʹԠ͍͚ͯ͡ • TIMTOWDY •
நͷίϯτϩʔϧ͕CDKʹΑΔಡΈ͍͢IaCͷΧΪ
StackͷڥքΛίϯτϩʔϧ͢Δ • Stackؒͷؔੑޙ͔Βม͑ʹ͍͘ → ઃܭ͕ඞཁ • దʹ͚ΔͨΊͷߟ͑ํͷྫ • ϓϩϏδϣχϯάͷΦϖϨʔγϣϯΛͲͷ୯ҐͰߦ͏͔ •
ෳͷStackͷߏʹڞ௨ͯ͠ґଘ͢ΔϦιʔεԿ͔
StackͷڥքΛίϯτϩʔϧ͢Δ (Tips) • StackؒͰϦιʔεͷґଘؔΛ࡞Δ͜ͱ͕Ͱ͖Δ • ͨͱ͑ɺStackͷϓϩύςΟͷConstructΛೖΕͯڞ༗Ͱ͖Δ • ଞͷStackͷConstructʹߦͬͨมߋͦΕΛ࣋ͭStackʹө • ഁյతͳૢ࡞͕Ͱ͖ͳ͍Α͏ʹInterfaceܕͰڞ༗͢Δ͠
ςετ • Snapshotςετ͚ͩͰेಋೖ͢ΔՁ͋Δ • յͣ͞ʹϦϑΝΫλϦϯάͰ͖Δ͔֬ೝͰ͖Δ • ΫϦςΟΧϧͳͱ͜Ζݸผͷςετॻ͍͓ͯ͘ͱΑΓ҆৺ • cdk.Contextͷmock͕ඞཁʹͳΔ߹͋ΔͷͰҙ •
طଘϦιʔεͷimportΛߦ͏߹contextʹґଘ͢Δҝ
·ͱΊ
·ͱΊ • CDKCloudFormationΛखܰʹ͑Δπʔϧ • ಠࣗͷ֓೦͕৭ʑͱొ͢ΔͷͰͪΌΜͱཧղͯ͠ѻ͏ͱྑ͍ • ಛʹConstructͲͷΑ͏ʹநԽ͞Ε͍ͯΔ͔ཧղ͕ඞཁ • ઃܭΛؒҧ͏ͱޙΓ͠ʹ͍͘ͷͰಛʹStackઃܭ৻ॏʹ
͓·͚
ϦϑΝΫλϦϯάͷ͓ڙʹ PerlͷϫϯϥΠφʔΛॻ͘ͱ ศརͩͧ
OWARI