Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Perl MongersのためのAWS_CDK入門
Search
karupanerura
February 19, 2021
180
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
89
Perl Meets \w+ あるいは開発を支えるPerl活用の実例集
karupanerura
0
76
log
karupanerura
1
110
Use Perl as Better Shell Script
karupanerura
0
910
GoでParserを書く
karupanerura
4
1.1k
マイ隙間家具OSSたちのご紹介
karupanerura
2
300
Mustache Template 話 2024
karupanerura
0
67
1つの言語を原点に色々な言語を学ぶということ
karupanerura
4
3.6k
Javaの実装をPerlでテストする
karupanerura
0
1.4k
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.2k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
200
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Technical Leadership for Architectural Decision Making
baasie
3
410
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.4k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
570
A Modern Web Designer's Workflow
chriscoyier
698
190k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
140
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
180
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