Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Stripeを組み込む際の CDK実装Tips/awsbasic-202202
Search
Hidetaka Okamoto (Stripe)
February 26, 2022
Technology
240
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Stripeを組み込む際の CDK実装Tips/awsbasic-202202
AWS エバンジェリストシリーズ AWSの基礎を学ぼうの登壇資料です。
https://awsbasics.connpass.com/event/235164/
Hidetaka Okamoto (Stripe)
February 26, 2022
More Decks by Hidetaka Okamoto (Stripe)
See All by Hidetaka Okamoto (Stripe)
Stripeではじめる Revenue Operations / jp_stripes_okinawa_8
stripehideokamoto
0
340
収益を高めるための Stripeダッシュボード活用術 / jp_stripes_online_7
stripehideokamoto
0
430
No-code SaaS and Full Site Editing / wcasia2023
stripehideokamoto
0
280
コア機能開発に集中するための Stripe Checkout活用法 / jp_stripes_deep_dive_202301
stripehideokamoto
0
570
State of Checkout 2022から見た オンライン決済フローの最適化/jp-stripes-miyzaki-202301
stripehideokamoto
0
260
サブスクリプション決済入門 Stripeでの実装方法と、要件定義時のポイント/okta-stripe-202301
stripehideokamoto
0
230
ノーコード・ローコードツールで サブスク運用を効率化する方法 / JP_Stripes_Osaka_202301
stripehideokamoto
0
180
ビジネスユーザを巻込む Stripeダッシュボード活用法 / jp_stripes_deepdive-202212
stripehideokamoto
0
380
AWSでローコードにはじめる サブスクリプション運用の効率化/aws-startup-tech-meetup-fukuoka-2
stripehideokamoto
0
200
Other Decks in Technology
See All in Technology
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
16
120k
AWS DevOps Agent スキルをつかいこなそう / Master AWS DevOps Agent Skills
kinunori
2
670
20260930_Gemma4_Hands-on
tsho
0
210
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
180
「とりあえず動く」の先へ。 AI時代のチーム開発と内部設計/2026-slsdays
slsops
0
110
大阪オフィスに Unitree Go2 がやってきたので Physical AI やってみた
dafujii
0
240
スキルを作る、その前に!複数人で使われるスキルを 作るためのプロセス
junkifurukawa
2
180
セルフサービスのオブザーバビリティ基盤をOpenTelemetryで作る / Building a Self-Service Observability Platform with OpenTelemetry
ymotongpoo
3
520
KanaAI
shreyas1009
0
140
Codex概要
ymiya55
0
240
HacobuにおけるFDEとは/登壇資料(戸井田 裕貴)
hacobu
PRO
1
710
OpenClawでAzure DevOpsのWiki更新を自動化する - クラウドAIだけでは届かない場所へ
yutakaosada
0
140
Featured
See All Featured
The browser strikes back
jonoalderson
0
1.7k
RailsConf 2023
tenderlove
30
1.6k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
The SEO identity crisis: Don't let AI make you average
varn
0
570
Mind Mapping
helmedeiros
1
390
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
Documentation Writing (for coders)
carmenintech
77
5.6k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
300
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.9k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Transcript
Stripeを組み込む際の CDK実装Tips AWS エバンジェリストシリーズ AWSの基礎を学ぼう Hidetaka Okamoto(@hide__dev) 2022/02/26
岡本 秀高 ( @hide__dev ) • Stripe Developer Advocate (ex-developer
in Digitalcube) • JavaScript / TypeScript developer • AWS / Next.js / WordPress / etc… • WordCamp Kyoto 2017 / JP_Stripes Connect 2019 / AWS Samurai 2017 / etc… • 🐈(猫フラご容赦) 2 ジャムジャム!!Jamstack_5 #awsbasics
3 https://jawsug.connpass.com/event/240422/
4 https://stripe.com/jp
サーバーサイドSDKで、簡単に決済系の組み込みが可能 5 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics const session = await
stripe.checkout.sessions.create({ mode: "payment", success_url: `${req.headers.origin}`, cancel_url: `${req.headers.origin}`, line_items:[{ price: req.body.price_id, quantity: 1 }] }) return session.url
6 そのコード、どこにどうやってデプロイしよう? AWS エバンジェリストシリーズ AWSの基礎を学ぼう
7 https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html
AWS CDKでServerless Functionを実装 8 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics # アプリをセットアップ
% mkdir new-cdk-app % cd new-cdk-app % cdk init –language typescript # ライブラリのインストールやファイルの配置 % npm install stripe % mkdir -p resources/functions/ % touch resources/functions/stripe.js # デプロイ % cdk deploy –watch
料金データを返すLambdaの例 9 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics const stripe = require('stripe')(process.env.STRIPE_SECRET_API_KEY);
exports.main = async function(event, context) { try { const { data } = await stripe.prices.list({ lookup_keys: [process.env.STRIPE_PRICE_LOOKUP_KEY] }) return { statusCode: 200, body: JSON.stringify(data) }; } catch(error) { const body = error.stack || JSON.stringify(error, null, 2); return { statusCode: 400, body: JSON.stringify(body) }; } }
LambdaをCDKで定義 10 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics import { Stack, StackProps
} from 'aws-cdk-lib'; import { Construct } from "constructs"; import * as lambda from "aws-cdk-lib/aws-lambda"; export class AwsCdkStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); const handler = new lambda.Function(this, "StripeHandler", { runtime: lambda.Runtime.NODEJS_14_X, // So we can use async in widget.js code: lambda.Code.fromAsset("resources/functions"), handler: "stripe.main", environment: { STRIPE_PRICE_LOOKUP_KEY: ‘lookup-key’, STRIPE_SECRET_API_KEY: 'sk_xxx' } }); }}
環境変数を何処に置こう? 11 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics import { Stack, StackProps
} from 'aws-cdk-lib'; import { Construct } from "constructs"; import * as lambda from "aws-cdk-lib/aws-lambda"; export class AwsCdkStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); const handler = new lambda.Function(this, "StripeHandler", { runtime: lambda.Runtime.NODEJS_14_X, // So we can use async in widget.js code: lambda.Code.fromAsset("resources/functions"), handler: "stripe.main", environment: { STRIPE_PRICE_LOOKUP_KEY: ‘lookup-key’, STRIPE_SECRET_API_KEY: 'sk_xxx' } }); } }
12 Secrets Managerの値を読み取る AWS エバンジェリストシリーズ AWSの基礎を学ぼう
Secrets Managerの値を環境変数に渡す例 13 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics import * as
sm from "aws-cdk-lib/aws-secretsmanager"; export class AwsCdkStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); const secret = sm.Secret.fromSecretAttributes(this, "ImportedSecret", { secretCompleteArn: "登録したSecretのARN" }); const handler = new lambda.Function(this, "StripeHandler", { environment: { STRIPE_PRICE_LOOKUP_KEY: secret.secretValueFromJson('lookup-key').toString(), STRIPE_SECRET_API_KEY: ‘sk_xxx’ } …
14 もっと安全に管理したい AWS エバンジェリストシリーズ AWSの基礎を学ぼう
LambdaにSecrets Managerへのアクセス権限を設定 15 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics const handler =
new lambda.Function(this, "StripeHandler", { runtime: lambda.Runtime.NODEJS_14_X, // So we can use async in widget.js code: lambda.Code.fromAsset("resources/functions"), handler: "stripe.main", environment: { STRIPE_PRICE_LOOKUP_KEY: secret.secretValueFromJson('lookup-key').toString(), } }); handler.addToRolePolicy(new iam.PolicyStatement({ resources: [secret.secretArn], actions: ['secretsManager:GetSecretValue'], }))
Secrets Managerの値を取得して、利用する 16 AWS エバンジェリストシリーズ AWSの基礎を学ぼう #awsbasics const AWS =
require('aws-sdk'); const Stripe = require('stripe'); exports.main = async function(event, context) { try { const secretsmanager = new AWS.SecretsManager(); const secrets = await secretsmanager.getSecretValue({ SecretId: 'secret-id' }) const secretsJSON = JSON.parse(secrets.SecretString) const stripe = new Stripe(secretsJSON.STRIPE_SECRET_API_KEY)
まとめ • AWS CDKを利用すると、アプリの実装言語でAWSインフラも定義できる • StripeなどのAPIキーを利用するSaaSを使う場合、 Secrets Manager / Systems
ManagerとCDKを組み合わせて、 テンプレートからキー情報を秘匿できる • テスト環境・本番環境の切り替えまでやりたい場合は、 CDKのContextを活用しよう https://docs.aws.amazon.com/cdk/v2/guide/get_context_var.html 17 AWS エバンジェリストシリーズ AWSの基礎を学ぼう
Thanks! • Twitterハッシュタグでシェア #awsbasics #JP_Stripes • Twitterアカウント: @hide__dev @StripeJapan •
QiitaでStripeに関する 開発ブログ更新中 https://qiita.com/organizations/stripe 18 AWS エバンジェリストシリーズ AWSの基礎を学ぼう