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
7.7k
それでも俺は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
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
1
1.2k
AWS CDK Conference Japan 2024 OP
tomoki10
0
630
TypeScripterに送るIaCの世界への招待〜AWS CDKと共に〜/inviting-typescripters-to-the-world-of-iac-with-aws-cdk
tomoki10
0
700
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.6k
CDK支部のこれまでとこれから / jaws-ug-cdk-past-and-future
tomoki10
1
860
AWS CDKでECS on FargateのCI/CDを実現する際の理想と現実 / ideal-and-reality-when-implementing-cicd-for-ecs-on-fargate-with-aws-cdk
tomoki10
21
26k
AWSCDKを通してAWSを学ぶ/learn AWS through AWS CDK
tomoki10
0
3.4k
Other Decks in Technology
See All in Technology
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
組織成長を加速させるオンボーディングの取り組み
sudoakiy
2
180
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
620
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
530
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
Engineer Career Talk
lycorp_recruit_jp
0
180
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
Application Development WG Intro at AppDeveloperCon
salaboy
0
190
生成AIが変えるデータ分析の全体像
ishikawa_satoru
0
160
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
4
230
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Building an army of robots
kneath
302
43k
Six Lessons from altMBA
skipperchong
27
3.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
890
How GitHub (no longer) Works
holman
310
140k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
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/