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
Jamstack開発者のための App Runner入門
Search
Hidetaka Okamoto
January 26, 2022
Programming
1
440
Jamstack開発者のための App Runner入門
JAWS-UG関西「コンテナ勉強会/App Runnerハンズオン(見るだけOK)もあるよ」登壇資料です。
Hidetaka Okamoto
January 26, 2022
Tweet
Share
More Decks by Hidetaka Okamoto
See All by Hidetaka Okamoto
OpenAI APIで API Changelogを要約してみた話 / chatgpt-osaka-1
hideokamoto
0
490
コミュニティ運営から 中の人に変わって感じたこと
hideokamoto
0
59
Developerが Developer Advocateになった話 / dev-rel-meetup-tokyo-71
hideokamoto
0
280
WordPressでの webサイト制作2022 / ngk2022s
hideokamoto
0
390
JavaScript(TypeScript)で メディアサイトを インフラから構築する方法 / jsconf-jp-2021
hideokamoto
2
4.1k
AWS上でStripeを利用したアプリをより安全にデプロイする方法 /jaws-pankration-2021
hideokamoto
1
170
Shifter Headlessと Headless WordPressの紹介
hideokamoto
0
1.7k
Stripe & Next.js + AWS Amplify で会員 + 定期課金機能 / JP_Stripes20210903
hideokamoto
7
3k
後付けで 従量課金プランの 提供を開始した話 / 20210609-jp_stripes
hideokamoto
0
190
Other Decks in Programming
See All in Programming
情報漏洩させないための設計
kubotak
5
1.2k
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
980
선언형 UI에서의 상태관리
l2hyunwoo
0
250
MCP with Cloudflare Workers
yusukebe
2
270
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
110
Zoneless Testing
rainerhahnekamp
0
150
GitHubで育つ コラボレーション文化 : ニフティでのインナーソース挑戦事例 - 2024-12-16 GitHub Universe 2024 Recap in ZOZO
niftycorp
PRO
0
1.1k
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
720
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.3k
快速入門可觀測性
blueswen
0
480
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
870
月刊 競技プログラミングをお仕事に役立てるには
terryu16
1
1.1k
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
266
13k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
850
Thoughts on Productivity
jonyablonski
68
4.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Invisible Side of Design
smashingmag
299
50k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
Music & Morning Musume
bryan
46
6.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Agile that works and the tools we love
rasmusluckow
328
21k
Transcript
Jamstack։ൃऀͷͨΊͷ App Runnerೖ JAWS-UG ؔ Hidetaka Okamoto 2022/1/27 #JAWS-UG
Ԭຊलߴ @hide__dev • Stripe Developer Advocate • JS / TS
Developer • AWS / Next.js / Serverless / shopify / … • 🐈 #JAWS-UG
2021/12ʹStripeʹδϣΠϯ͠·ͨ͠
Facebook “JP_Stripes” https://bit.ly/3G2Fh6D
Agenda • Next.jsΞϓϦΛApp RunnerʹσϓϩΠͯ͠Έͨ • JamstackͳαΠτɾΞϓϦΛެ։͢ΔͨΊͷՃ࡞ۀ • AWS AmplifyͱAWS App
RunnerɺͲ͕͍͍ͬͪʁ #JAWS-UG
Agenda • Next.jsΞϓϦΛApp RunnerʹσϓϩΠͯ͠Έͨ • JamstackͳαΠτɾΞϓϦΛެ։͢ΔͨΊͷՃ࡞ۀ • AWS AmplifyͱAWS App
RunnerɺͲ͕͍͍ͬͪʁ #JAWS-UG
GitHubʹNext.jsͷϦϙδτϦΛ༻ҙ͓ͯ͘͠
ϚωʔδϝϯτίϯιʔϧʹΞΫηε
GitHubͷ߹ιʔείʔυϦϙδτϦΛબ
GitHubʹΞϓϦΠϯετʔϧ
ϦϙδτϦΞΫηεΛߜΔ͜ͱՄೳ
connectionͷ໊લΛ͚͓ͭͯ͘
Connector / repo / branchࢦఆ
σϓϩΠΛࣗಈʹ͢Δ͔ΛܾΊΔ
ߏஙઃఆGUI͚ͩͰ݁Ͱ͖ΔʢίʔυՄʣ
Next.jsඪ४ઃఆͷ ߹ • ϥϯλΠϜ: Nodejs12 (or later) • ߏίϚϯυ
yarn && yarn build • ։࢝ίϚϯυ yarn start • ϙʔτ: 3000
ίϯςφαʔϏεͷઃఆ
ઃఆͰ͖Δ༰ • CPU / ϝϞϦ / ڥม • Φʔτεέʔϧ •
ϔϧενΣοΫ • Πϯελϯεϩʔϧ • KMSΩʔ • λά #JAWS-UG
ݸਓతཁνΣοΫϙΠϯτ • Φʔτεέʔϧͷ࠷େαΠζ͕σϑΥϧτ25 • εέʔϧ։࢝ͷج४ಉ࣮࣌ߦʢ㲈ϦΫΤετʣ • DynamoDBͳͲʹΞΫηε͍ͤͨ͞ͳΒɺΠϯελϯεϩʔϧඞਢ • ଓ͢ΔαʔϏε͕ଟ͍ͳΒɺ
GUI͡Όͳ͘CDKͳͲͰߏཧΛਪ #JAWS-UG
ઃఆΛϨϏϡʔͯ͠ σϓϩΠ #JAWS-UG
ͭ
τϥϒͬͨΒϩάΛݟΔ
εςʔλε RunningʹͳΕOK
Agenda • Next.jsΞϓϦΛApp RunnerʹσϓϩΠͯ͠Έͨ • JamstackͳαΠτɾΞϓϦΛެ։͢ΔͨΊͷՃ࡞ۀ • AWS AmplifyͱAWS App
RunnerɺͲ͕͍͍ͬͪʁ #JAWS-UG
ެ։લʹΔͰ͋Ζ͏Ճ࡞ۀ • CloudFrontͰCDNΛઃఆ͢Δ • CloudFrontʹACMͰSSLূ໌ॻΛઃఆ • Route53ͰυϝΠϯΛઃఆ #JAWS-UG
ACMʢSSLূ໌ॻʣͲ͜ʹ͚ͭΔʁ • App RunnerͰূ໌ॻΛઃఆͰ͖Δ • CloudFrontʹ͚ͩઃఆͯ͠ಈ͖͢Δ༷ࢠ • ҆શੑΛͱΔͳΒCF / Runner྆ํͰ͚ͭͨ΄͏͕Α͍͔
#JAWS-UG
AWS CDKͰߏཧ͢Δͱָͦ͏ new apprunner.Service(this, 'Service', { source: apprunner.Source.fromGitHub({ repositoryUrl: 'https://github.com/aws-containers/hello-app-runner',
branch: 'main', configurationSource: apprunner.ConfigurationSourceType.API, codeConfigurationValues: { runtime: apprunner.Runtime.PYTHON_3, port: '8000', startCommand: 'python app.py', buildCommand: 'yum install -y pycairo && pip install -r requirements.txt', }, connection: apprunner.GitHubConnection.fromConnectionArn('CONNECTION_ARN'), }), }); #JAWS-UG
Agenda • Next.jsΞϓϦΛApp RunnerʹσϓϩΠͯ͠Έͨ • JamstackͳαΠτɾΞϓϦΛެ։͢ΔͨΊͷՃ࡞ۀ • AWS AmplifyͱAWS App
RunnerɺͲ͕͍͍ͬͪʁ #JAWS-UG
Q. AWS Amplify͡ΌͩΊͳͷʁ #JAWS-UG
A. First ChoiceAmplify App Runnerͷग़൪͋Δ #JAWS-UG
Why? #JAWS-UG
AWS Amplify (Next.js SSR/ISR)Lamnda@Edge • ಈ͖ͱͯ͠ɺserverless-nextjsʹ͍ۙʢͱ͍ΘΕ͍ͯΔʣ • Next.jsΛෳͷLamnda@EdgeʹσϓϩΠ • CloudFront
- Lamnda@Edge - S3ߏʹͳΔ • ΤοδͰಈ͘ͷͰɺૣ͍ɻ ISRͰ͖Δɻnodejs14͑Δ • ͨͩ͠Lamnda@Edgeͷ੍ݶʹनΘΕΔ #JAWS-UG
Lambda@Edgeͷ੍ݶͰNext.jsͭΒ͍ͭ • ϩάݺͼग़͠ݩͷϦʔδϣϯ͕҆ఆ͠ͳ͍ • ΞΫηεͷ͋ͬͨϦʔδϣϯͷCLWʹϩά͕ग़Δ • AWS APIݺͼग़࣌͠ʹϦʔδϣϯࢦఆඞਢ • Lambdaʹڥม͕ઃఆͰ͖ͳ͍
• σϓϩΠύοέʔδͷ༰ྔ͕࠷େ50MB(ΦϦδϯ) #JAWS-UG
Ͳ͏͍͏Ҋ݅ͰAmplify͕ਏ͘ͳΔʁ • Next.jsͷAPIΛΰϦΰϦʹ࣮͢ΔλΠϓ • APIʹڥมΛͨ͘͠ͳΔͱɺͪΐͬͱͨ͠ͰSSMඞਢʹ • ґଘϥΠϒϥϦͷଟ͍େنΞϓϦ • ϏϧυޙͷΞϓϦαΠζͷνΣοΫਪ •
ίϯςφΠϝʔδͰཧ͍ͨ͠߹App Runner͚͔͠Εͳ͍ #JAWS-UG
serverless-nextjsCDKཧͯ͠͠·͏ख͋Δ import { NextJSLambdaEdge } from "@sls-next/cdk-construct"; import { Certificate
} from "@aws-cdk/aws-certificatemanager"; export class ServerlessNextjsCdkExampleStack extends cdk.Stack { constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); const app = new NextJSLambdaEdge(this, "NextJsApp", { serverlessBuildOutDir: "./build", domain: { domainNames: ["wp-kyoto.net"], certificate: Certificate.fromCertificateArn( this, "WPKYOTOACM", “arn:aws:acm:us-east-1:999999:certificate/123-456-789“ ), }, }); #JAWS-UG
Amplify -> serverless-nextjs -> App Runner • ӈʹߦ͘΄ͲAWSʹґଘ͠ͳ͘ͳΔ • AmplifyCLI͕࡞ΔίʔυΛͲΕ͘Β͍ڐ༰͢Δ͔࣍ୈ͔
• ݸਓతʹnot for meͳͷͰɺCDKͰࣗલཧத • CDKͰߏཧ͢ΕIAMͳͲͷઃఆΛTakeOver͍͢͠ #JAWS-UG
·ͱΊ • AWSͰNext.jsɺͱΓ͋͑ͣAmplifyͰOK • ͨͩ͠serverless-nextjsབྷΈͷ੍ʹ᪴͘έʔεʹཁҙ • AmplifyͰಈ͔ͤͳ͘ͳͬͨΒɺApp Runner • App
RunnerΛΔ͜ͱͰɺʮ࣍ͷखʯ͕खʹೖΔ • ޙฤͷϫʔΫγϣοϓͰͥͻମݧͯ͠ΈΑ͏ʂ #JAWS-UG
Stripe / Jamstack / WordPress <> AWS ొஃػձ୳ͯ͠·͢ • Stripe
Webhook -> AWS Step Functions / AppSync / etc… • Stripe SDK <> Lambda / Secrets Manager / AWS Amplify / etc… • AWS Amplify <> Next.js / Gatsby / Ionic / Capacitor / etc… • WordPress <> EC2 / Systems Manager / CloudFront / etc… #JAWS-UG