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.9k
それでも俺は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
re:Invent2024のIaC周りのアップデート&セッションの共有/around-re-invent-2024-iac-updates
tomoki10
0
740
Classmethod流のPlatform Engineering / classmethod-platform-engineering-devio2024
tomoki10
1
1.3k
AWS CDK Conference Japan 2024 OP
tomoki10
0
680
TypeScripterに送るIaCの世界への招待〜AWS CDKと共に〜/inviting-typescripters-to-the-world-of-iac-with-aws-cdk
tomoki10
0
720
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
CDK支部のこれまでとこれから / jaws-ug-cdk-past-and-future
tomoki10
1
870
AWS CDKでECS on FargateのCI/CDを実現する際の理想と現実 / ideal-and-reality-when-implementing-cicd-for-ecs-on-fargate-with-aws-cdk
tomoki10
21
27k
Other Decks in Technology
See All in Technology
ナレッジベースはどのようにSQLを生成するのか / Knowledge Bases supports structed data retrieval
hayaok3
2
180
Password-less Journey - パスキーへの移行を見据えたユーザーの準備 @ AXIES 2024
ritou
2
1.1k
B10-ひと目でわかる(といいなぁ)Microsoft Purview
seafay
PRO
0
620
Explain EXPLAIN
keiko713
10
2.9k
問題を認識して解決できる人は何でもできる
i999rri
0
120
Autonomous Database サービス・アップデート (FY25)
oracle4engineer
PRO
0
280
【AWS re:Invent 2024】Amazon Bedrock アップデート総まとめ
minorun365
PRO
7
660
知らない景色を見に行こう チャンスを掴んだら道が開けたマネジメントの旅 / Into the unknown~My management journey~
kakehashi
10
1.2k
A/Aテストにおけるサンプルサイズ/japanr2024
nikkei_engineer_recruiting
1
630
Replit Agent
kawaguti
PRO
2
210
アジャイルテストの4象限で考える プロダクト開発の品質への向き合い方
nagano
1
980
How is Cilium Tested?
yutarohayakawa
5
310
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
136
6.7k
Building an army of robots
kneath
302
44k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
260
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Site-Speed That Sticks
csswizardry
1
160
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Faster Mobile Websites
deanohume
305
30k
What's in a price? How to price your products and services
michaelherold
243
12k
Making the Leap to Tech Lead
cromwellryan
133
9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
How to Think Like a Performance Engineer
csswizardry
21
1.2k
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/