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
それでも俺はAWS CDKが作るリソースに物理名を付けたい 〜CDKのベストプラクティスは本当...
Search
tomoki10
April 09, 2022
Technology
1
8k
それでも俺はAWS CDKが作るリソースに物理名を付けたい 〜CDKのベストプラクティスは本当にベストなのか〜 / AWS CDK resource name can be a physical name
AWS CDK Conference Japan で発表した内容です。
https://jawsug.connpass.com/event/240422/
tomoki10
April 09, 2022
Tweet
Share
More Decks by tomoki10
See All by tomoki10
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
230
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
500
re:Invent2024のIaC周りのアップデート&セッションの共有/around-re-invent-2024-iac-updates
tomoki10
0
1k
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
1
1.3k
AWS CDK Conference Japan 2024 OP
tomoki10
0
700
TypeScripterに送るIaCの世界への招待〜AWS CDKと共に〜/inviting-typescripters-to-the-world-of-iac-with-aws-cdk
tomoki10
0
740
AWSでもBuildpacksを使ってDockerfileレスに出来るのか!?/can-i-use-buildpacks-to-go-dockerfile-less-in-aws
tomoki10
0
2.8k
ECS on Fargate のセキュリティ対策は何をやるべき?開発者目線で考える/security-for-ecs-on-fargate-secjawsdays
tomoki10
14
11k
AWS CDKの最強の書き方を実践してみる 2023年版/practice-the-strongest-writing-method-of-aws-cdk-2023-edition
tomoki10
4
6.7k
Other Decks in Technology
See All in Technology
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
180
能動的ドメイン名ライフサイクル管理のすゝめ / Practice on Active Domain Name Lifecycle Management
nttcom
0
200
サーバーなしでWordPress運用、できますよ。
sogaoh
PRO
0
120
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
430
[トレノケ雲の会 mod.13] 3回目のre:Inventで気づいたこと -CloudOperationsを添えて-
shintaro_fukatsu
0
110
LINEヤフーのフロントエンド組織・体制の紹介【24年12月】
lycorp_recruit_jp
0
540
[JAWS-UG新潟#20] re:Invent2024 -CloudOperationsアップデートについて-
shintaro_fukatsu
0
120
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
130
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
280
コンテナセキュリティのためのLandlock入門
nullpo_head
2
330
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
27
23k
事業貢献を考えるための技術改善の目標設計と改善実績 / Targeted design of technical improvements to consider business contribution and improvement performance
oomatomo
0
150
Featured
See All Featured
For a Future-Friendly Web
brad_frost
175
9.4k
The Pragmatic Product Professional
lauravandoore
32
6.3k
Facilitating Awesome Meetings
lara
50
6.1k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
What's in a price? How to price your products and services
michaelherold
243
12k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
The Cult of Friendly URLs
andyhume
78
6.1k
Transcript
AWS CDK Conference Japan ͦΕͰԶAWS CDK͕࡞ΔϦιʔεʹཧ໊Λ͚͍ͨ ʙCDKͷϕετϓϥΫςΟεຊʹϕετͳͷ͔ʙ CXࣄۀຊ෦ IoTࣄۀ෦ 2022/04/09
ࠤ౻ஐथ 1
ࣗݾհ @tmk2154 @tomoki10 • ࠤ౻ஐथ • Ϋϥεϝιουגࣜձࣾ • CXࣄۀຊ෦ IoTࣄۀ෦
• ݱࡏɿαʔόʔαΠυ݉ΠϯϑϥΤϯδχΞ ݉QAͱ͔AWSΞΧϯτͷηΩϡϦςΟ • झຯɿAPEXɺࢄา • ͖ͳAWSαʔϏεɿLambdaɺCDK
AWS CDKͷϕετϓϥΫςΟεͰϦιʔεͷࣗಈ໊͚͕ਪ͞Εͯ·͢ ͚Ͳɺࣗಈ໊͚ͷϦιʔε໊ਏ͘ͳ͍Ͱ͔͢ʁʁ 3 ఏى Fargate Cluster/ServiceͱConstructͷidʹڥ໊+ݻఆ໊+Ϧιʔε໊Λઃఆͨ͠߹ͷදࣔྫ
4 ઌਓͷݴ༿ https://www.amazon.co.jp/ιϑτΣΞΞʔΩςΫνϟͷجૅ-—ΤϯδχΞϦϯάʹجͮ͘ମܥతΞϓϩʔν-Mark-Richards/dp/4873119820/ ʮΞʔΩςΫτʹաڈͷ͔࣌Β͞Ε͍ͯΔ લఏެཧΛٙ͏ͱ͍͏ॏཁͳ͕͋Δʯ P.viiΑΓ
5 ࣍ • AWS CDKϕετϓϥΫςΟεͱ • ࠓճऔΓ্͛Δ߲ • Ϧιʔεͷࣗಈ໊͚ͷ֓ཁ •
ͱߟ͑Δཧ༝ • ղܾࡦ
6 AWS CDKϕετϓϥΫςΟεͱ AWS CDKͷϕετϓϥΫςΟεʹ͍ͭͯॻ͔ΕͨAWSϒϩά https://aws.amazon.com/jp/blogs/news/best-practices-for-developing-cloud-applications-with-aws-cdk/ ओͳ༰ • CDKͷֶ •
৫ͰͷऔΓΉࡍͷ৺ಘ • ίʔυཧํ๏ • ConstructϥΠϒϥϦͷϕετϓϥΫςΟε • AWS CDK ΞϓϦέʔγϣϯͷ ϕετϓϥΫςΟε
7 AWS CDKϕετϓϥΫςΟεͱ AWS CDKͷϕετϓϥΫςΟεʹ͍ͭͯॻ͔ΕͨAWSϒϩά https://aws.amazon.com/jp/blogs/news/best-practices-for-developing-cloud-applications-with-aws-cdk/ ओͳ༰ • CDKͷֶ •
৫ͰͷऔΓΉࡍͷ৺ಘ • ίʔυཧํ๏ • ConstructϥΠϒϥϦͷϕετϓϥΫςΟε • AWS CDK ΞϓϦέʔγϣϯͷ ϕετϓϥΫςΟε
8 ϕετϓϥΫςΟε·ͩૣ͍ͱײͨ͡Β ॳ~தڃऀ͚ͷͰҎલొஃͨ͠ͷͰͪ͜Βݟ͍ͯͩ͘͞(એ) https://dev.classmethod.jp/articles/aws-devday-online-japan-know-how-from-initial-development-to-operation-on-how-to-use-aws-cdk/ ओͳ༰ • CDKͷ෦ߏͷུ֓ • ։ൃ࣌Α͘Ή෦ͷิ •
։ൃ࣌ͷϊϋ • ύΠϓϥΠϯߏங࣌ͷબࢶ • ӡ༻࣌ͷϊϋ
9 AWS CDK ΞϓϦέʔγϣϯͷϕετϓϥΫςΟε ॻ͔Ε͍߲ͯͨ(Օॻ͖ɿ໊߲ɺվߦԼͷίϝϯτɿࣗͷղऍ) • σϓϩΠ࣌Ͱͳ͘ɺ߹࣌ʹܾఆ͢Δ CfnͷύϥϝʔλͰͳ͘CDKͷςϯϓϨʔτੜ࣌ʹΛຒΊࠐ͏ • ࣗಈͰੜ͞ΕΔϦιʔε໊Λ༻͠ɺཧతͳ໊લΛ༻͠ͳ͍
• σϓϩΠཁ݅ʹԠͯ͡ɺΞϓϦέʔγϣϯͷStageΛෳͷStackʹׂ͢Δ ᘳͳਖ਼ղͳ͍͕ελοΫঢ়گʹԠׂͯ͡ • cdk.context.jsonΛίϛοτͯ͠ɺ֎෦తͳཁҼͰ߹݁Ռ͕มΘͬͯ͠·͏͜ͱΛආ͚Δ ҙਤͤͣϦιʔεͷߋ৽͕ൃੜ͠ͳ͍Α͏ʹ͢ΔͨΊͷܙ • AWS CDKͰϩʔϧͱηΩϡϦςΟάϧʔϓΛཧͰ͖ΔΑ͏ʹ͢Δ CDKͰҰ෦ఏڙ͞Ε͍ͯΔϩʔϧηΩϡϦςΟάϧʔϓੜػೳΛ͏ͱ࠷খݖݶͰ࣮͍͢͠ • શͯͷStageΛίʔυͰϞσϧԽ͢Δ ڥ͝ͱʹStackϑΝΠϧΛ࡞Βͣɺڥ͝ͱͷύϥϝʔλͰΓସ͑Δͱڥࠩҟ͕࠷খʹͳΔ • શͯΛଌఆ͢Δ ϝτϦΫεμογϡϘʔυͳͲΛ࡞ΕΔϝιουΛ׆༻͠Α͏
10 AWS CDK ΞϓϦέʔγϣϯͷϕετϓϥΫςΟε ॻ͔Ε͍߲ͯͨ(Օॻ͖ɿ໊߲ɺվߦԼͷίϝϯτɿࣗͷղऍ) • σϓϩΠ࣌Ͱͳ͘ɺ߹࣌ʹܾఆ͢Δ CfnͷύϥϝʔλͰͳ͘CDKͷςϯϓϨʔτੜ࣌ʹΛຒΊࠐ͏ • ࣗಈͰੜ͞ΕΔϦιʔε໊Λ༻͠ɺཧతͳ໊લΛ༻͠ͳ͍ɹɹˡ
ʂʂʂʂʂʂʂʂʂʂʂʂ • σϓϩΠཁ݅ʹԠͯ͡ɺΞϓϦέʔγϣϯͷStageΛෳͷStackʹׂ͢Δ ᘳͳਖ਼ղͳ͍͕ελοΫঢ়گʹԠׂͯ͡ • cdk.context.jsonΛίϛοτͯ͠ɺ֎෦తͳཁҼͰ߹݁Ռ͕มΘͬͯ͠·͏͜ͱΛආ͚Δ ҙਤͤͣϦιʔεͷߋ৽͕ൃੜ͠ͳ͍Α͏ʹ͢ΔͨΊͷܙ • AWS CDKͰϩʔϧͱηΩϡϦςΟάϧʔϓΛཧͰ͖ΔΑ͏ʹ͢Δ CDKͰҰ෦ఏڙ͞Ε͍ͯΔϩʔϧηΩϡϦςΟάϧʔϓੜػೳΛ͏ͱ࠷খݖݶͰ࣮͍͢͠ • શͯͷStageΛίʔυͰϞσϧԽ͢Δ ڥ͝ͱʹStackϑΝΠϧΛ࡞Βͣɺڥ͝ͱͷύϥϝʔλͰΓସ͑Α͏ • શͯΛଌఆ͢Δ ϝτϦΫεμογϡϘʔυͳͲΛ࡞ΕΔϝιουΛ׆༻͠Α͏
11 ϕετϓϥΫςΟεͷৄࡉ ࣗಈͰੜ͞ΕΔϦιʔε໊Λ༻͠ɺཧతͳ໊લΛ༻͠ͳ͍
ཧ໊Λ͏߹ͷσϝϦοτ • ΠϯϑϥͷҰ෦ΛෳσϓϩΠ͢Δ͜ͱ͕Ͱ͖ͳ͍ • Ϧιʔεʹഁյతมߋ͕͏߹ɺ࠶࡞ʹࣦഊ͢Δ 12 ϕετϓϥΫςΟεͷৄࡉ Amazon DynamoDB AWS
CDK Table A Hoge Table A Fuga Amazon DynamoDB AWS CDK Table A ཧ໊Λݻఆ͠ͳ͍߹ ཧ໊Λݻఆ͢Δ߹ 1ճ 2ճ ςʔϒϧ ࡞ ςʔϒϧ ࡞ 1ճ 2ճ
ܦݧ͔Βཧ໊Λ͏߹ͷσϝϦοτ • আ࣌ͷϙϦγʔΛอޢ(RemovalPolicy.RETAIN)Ͱઃఆͨ͠/͞ΕͯΔ߹ ελοΫআޙɺ࠶σϓϩΠ࣌ʹલճ࣮ߦͨ͠Ϧιʔε͕ॏෳࣦ͠ഊ͢Δ ҙਤͤͣอޢઃఆʹͳ͍ͬͯΔϦιʔε͕͋ΔͱσϓϩΠ͢Δ·Ͱؾ͚ͮͳ͍ 13 ཧ໊ͷσϝϦοτ AWS CDK AWS
CDK ཧ໊Λݻఆ͠ͳ͍߹ ཧ໊Λݻఆ͢Δ߹ 1ճ 2ճ Lambda ࡞࣌ Lambda ࡞࣌ 1ճ 2ճ Amazon CloudWatch Amazon CloudWatch Logs Hoge Logs Fuga Logs
14 ຊʹͦ͏͔ࠓҰٙͬͯΈΔ
ཧ໊Λ͏߹ͷσϝϦοτ • ΠϯϑϥͷҰ෦ΛෳσϓϩΠ͢Δ͜ͱͰ͖ͳ͍ →ෳਓ։ൃ࣌ͷఆ?Ϧιʔε໋໊نଇCDKͷίʔυͱCfnͷ༷Λಡ·ͳ͍ͱ͔Βͣ ɹࣅͨΑ͏ͳ໊લͷϦιʔε͕ෳͰ͖Δͱؔ࿈͕͔ΒͣٯʹෆศͰʁ →Ϧιʔε໊ͷিಥ໋໊نଇ(ex.Ϧιʔεʹݸਓ͝ͱͷڥ໊Λ͚Δ)ͰճආՄೳ →ͦͦStack໊͕ҟͳͬͯConstructͷid͕ಉͩ͡ͱॏෳ͢ΔϦιʔε͕Ұ෦ଘࡏ͢Δ • Ϧιʔεʹഁյతมߋ͕͏߹ɺ࠶࡞ʹࣦഊ͢Δ →ྫʹ͋ΔDynamoDBͷKeySchemaͷมߋςʔϒϧ͕Ұഁغ͞ΕΔ
ɹϢʔβଆͦͷةݥੑʹؾ͚ͮΔΑ͏ʹ࡞ʹࣦഊͨ͠ํ͕ྑ͍ͷͰʁ 15 ϕετϓϥΫςΟεͷৄࡉ
ࢀরΕϩά ࢀরΕϩά • ࠶σϓϩΠ࣌ʹલճ࣮ߦͨ͠Ϧιʔε໊͕ॏෳ͠ͳ͍ →ҎલͷϦιʔεΔͷͰ͜·Ίʹআ͠ͳ͍ͱେྔʹϦιʔε͕Γ ɹͲΕ͕ݟ͍ͨͷ͔ɺআͯ͠ྑ͍ͷ͔͕͔ΓͮΒ͘ͳΔ 16 ϕετϓϥΫςΟεͷৄࡉ AWS CDK
1ճ Logs AWS CDK 2ճ࠶σϓϩΠ Logs Logs AWS CDK nճ࠶σϓϩΠ Logs Logs Logs Logs Logs Logs Logs Logs ;͏ɺ៉ྷʹͳͬͨͧʂ ͲͷϩάΛ ݟΕྑ͍ͷʁ ։ൃऀ
17 ผελοΫͰಉ͡ϦιʔεΛ࡞Δܙ https://speakerdeck.com/tomoki10/know-how-from-initial-development-to-operation-on-how-to-use-aws-cdk?slide=11
18 ผελοΫͰಉ͡ϦιʔεΛ࡞Δܙ ը૾Ҿ༻ݩɿ https://aws.amazon.com/jp/blogs/aws/boost-your-infrastructure-with-cdk/ new dynamodb.Table(this, `${id}-items`, { tableName: `${id}-items`,
partitionKey: { name: "itemId", type: dynamodb.AttributeType.STRING, }, }); const app = new cdk.App(); new UserAStack(app, `${envName}-${projectName}-UserAStack`, {} ); ໋໊نଇ͕ϦιʔεͰҟͳΓҰ෦(Aurora/WAFͳͲ) ελοΫ໊͕ҟͳͬͯϦιʔε໊͕ಉ͜͡ͱ͋Δ ͷͰ id Λ͚ͭΔ͜ͱͰॏෳΛճආͰ͖Δ envNameͱprojectNamecdk.json͔Βೖ͢Δ envNameݸਓ͝ͱ projectNamePJΛࣝผ͢ΔͨΊઃఆ
ௐࠪ/ӡ༻ͰԿ֬ೝ͢Δ߹ɺରͷϦιʔε͕͔Γʹͯ͘͘ਏ͍ 19 ܦݧ͔Βࣗಈ໊͚ͷ߹ͷਏ͍෦ Fargate Cluster/ServiceͱConstructͷidʹڥ໊+ݻఆ໊+Ϧιʔε໊Λઃఆͨ͠߹ͷදࣔྫ
• ೝෛՙͷதͷࡏੑೝ(ࠓճௐࠪʹඞཁͳهԱ)ෛՙ͕ߴ͘ͳΔ →։ൃௐࠪͳͲຊདྷ࣮ࢪ͍ͨ͠࡞ۀ༻ͷϫʔΩϯάϝϞϦ͕গͳ͘ͳΔ →ർฐ͠ੜ࢈ੑԼ(ݸਓͷײͰ͢) • ҰͭϦιʔεΛࣗಈͰ͚ͭΔͱCloudWatch LogsͷϩάάϧʔϓͳͲ ؔ࿈͢ΔϦιʔεࣗಈͰ໊͚͞ΕΔ 20 ܦݧ͔Βࣗಈ໊͚ͷ߹ͷਏ͍෦
͍͍ͨ ϦιʔεA ϦιʔεAͷ ϋογϡ໊ ϦιʔεA͕ ؔ࿈ͯ͠ੜ ͨ͠ϦιʔεB ϦιʔεBͷ ϋογϡ໊
21 ϕετϓϥΫςΟεΛ͋ΒͨΊͯݟฦ͢
22 ϕετϓϥΫςΟεΛ͋ΒͨΊͯݟฦ͢
23 Ͱ͖·ͤΜͰͨ͠ʂ
24 ݁ہϦιʔε໊Ͳ͏͖͔͢ ࣗͳΓͷ݁ • ։ൃ/ௐࠪ/ӡ༻ͳͲͰΑ֬͘ೝ͢ΔϦιʔε໊લΛݻఆ͢Δ αʔϏεͷྫ • ECSLambdaͳͲͷίϯϐϡʔςΟϯάαʔϏε • DynamoDBS3ͳͲͷετϨʔδ
• μογϡϘʔυ໊Ξϥʔτ໊ • ্هҎ֎ͷαʔϏεͰ͖Δ͚ͩݻఆ͠ͳ͍
25 ·ͱΊ • CDKͷϕετϓϥΫςΟε͕ຊ͔վΊͯߟ͑ͯΈͨ • ެཧΛٙ͏͜ͱΞʔΩςΫτͷ • ࣗಈͰੜ͞ΕΔϦιʔε໊Λ༻͠ɺཧతͳ໊લΛ༻͠ͳ͍ • ϕετϓϥΫςΟεͰड़ΒΕ͍ͯΔརΛվΊͯ֬ೝ
• ϕετͰͳ͔ͬͨܦݧͷհ • ζϘϥͳਓؒ(ࢲ)ͷ߹ɺෆཁϦιʔε͕େྔʹΔ • ࣗಈϦιʔε໊Ͱೝෛՙ͕ߴ͘ͳΔ • Ϧιʔε໊ͷࣗಈੜ΄Ͳ΄Ͳʹɻਏ͍࣌ݻఆԽ͠Α͏
26 additional JAWS CDK Λ্ཱ͍͖͍ͪ͛ͯͨʂͬͱݟΛڞ༗͍ͨ͠ʂ CDKͷݟΛൃද͍ͨ͠ํCDKΛΓ্͍͛ͨํืूʂʂ CDK @tmk2154 #jawsug-cdk νϟϯωϧ
https://jaws-ug.jp/jaws-ug-slack/