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 サーバレス設計 Tips集
Search
Atsushi Satou
May 15, 2024
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AWS サーバレス設計 Tips集
Atsushi Satou
May 15, 2024
More Decks by Atsushi Satou
See All by Atsushi Satou
AWS ECSでサービス間通信についておさらい
atsuw0
1
140
図で理解するAWS Network Firewallのアーキテクチャ
atsuw0
0
480
CLIで構築した方が良いもの一覧.pdf
atsuw0
0
190
HCP Terraformを使ったら AWSやGCPの環境構築が捗った話
atsuw0
0
310
HashicorpCloudについて.pdf
atsuw0
0
34
HCP Terraform について
atsuw0
0
1.9k
HashicorpCloudについて.pdf
atsuw0
0
39
AWS re:Invent 2023 ストレージ EFSレプリケーションのフェイルバック機能を試してみた
atsuw0
0
440
AWS re:Invent 2023 個人的に興味深いもの集
atsuw0
0
130
Featured
See All Featured
KATA
mclloyd
PRO
35
15k
HDC tutorial
michielstock
2
770
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.5k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
380
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
260
Believing is Seeing
oripsolob
1
180
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
450
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
200
Transcript
AWS サーバレス設計 Tips集 佐藤 淳 Serverless LT初心者向け LT大会 #45 https://serverlesslt.connpass.com/event/316406/
自己紹介 名前: 佐藤 淳 ( Atsushi Sato ) 会社: 某AWSが得意な会社
Qiita: https://qiita.com/atw0_0w 職業: インフラエンジニア 最近興味あること: golangでCLIツールの作成
今日話す内容 AWS 上でサーバレスアーキテクチャを構成してみて個人的に事前に検討し たほうが良いと思ったTips集になります。 ※ ブログで寄稿した内容メインで話します。 AWS クラウドサービス: AWS 対象サービス:
Lambda、 API Gateway
本日お話するAWS アーキテクチャ API Gateway + Lambda のシンプルな構成
Tips1 API Gateway
API を バージョンごとに公開 各バージョンでAPIを公開 [Tips 1] API Gateway + Lambda
APIバージョン管理
[Tips 1] API Gateway + Lambda APIバージョン管理 API Gateway …
${stageVariables.変数名} を使用してステージ変 数で設定した値のLambdaエイリアスにリクエスト https://docs.aws.amazon.com/ja_jp/apigateway/latest/developerguide/aws-api-gateway-stage-variables-reference.html
[Tips 1] API Gateway + Lambda APIバージョン管理 Lambda … API
Gatewayのステージ変数と同じLambdaエイリアス 名を指定
[Tips 1] API Gateway + Lambda APIバージョン管理 ユースケース: - バージョンごとにAPIを公開したい場合
詳しくは以下のリンクを参照 元ネタ: https://qiita.com/atw0_0w/items/c8b27cd4895fc6be9e98
Tips2 Lambda 検証
ローカルでLamdbaを試したいなら 「https://gallery.ecr.aws/lambda 」 からイメージを取得し、コンテナを実行 例) Lambda で Python を使用したい場合 https://gallery.ecr.aws/lambda/python
[Tips 2] ローカルでLambdaのベースコンテナを試してみたい
[Tips 2] ローカルでLambdaのベースコンテナを試してみたい
[Tips 2] ローカルでLambdaのベースコンテナを試してみたい ユースケース - ローカル上での動作確認 - Lambdaコンテナでカスタムイメージを利用したい場合 - デプロイ後の「invalid
ELF header」エラーの回避 > ローカル端末でのpythonとAWS Lambda 上でのpythonライブラリではOS自体が異なることでELF ヘッダー情報が異なることで 発生するエラー 詳しくは以下のリンクを参照 元ネタ: https://qiita.com/atw0_0w/items/2362dced7e8987210698
Tips3 Lambda Layer
複数のLambdaで呼び出されるケース [Tips 3] Lambda Layerを試す
[Tips 3] Lambda Layerを試す ユースケース - 複数の関数で共通で実行するコード - 外部パッケージを利用する場合 詳しくは以下のリンクを参照
元ネタ: https://qiita.com/atw0_0w/items/5fbb1ce89454baead818 https://qiita.com/atw0_0w/items/2362dced7e8987210698
[Tips 3] Lambda Layerを試す [補足] 外部パッケージを利用している場合の注意点 サーバーワークスさんの記事で興味深い記事を紹介。 > https://blog.serverworks.co.jp/lambda-function-stopped-working-suddenly 要約するとboto3
や botocore などと依存関係を持つライブラリでバージョン互換性に よるエラーが発生する事象。 → Lambdaのランタイムはデフォルトでランタイムバージョンは常に更新され、それに伴い各ライブラリのバージョンも更新される。 → 全く更新がないパッケージの利用やLayerだけ塩漬け対応していると依存関係のエラー発生するかも。。 ランタイムを手動更新する設定をすれば少なくともエラーは回避。
[Tips 3] Lambda Layerを試す ランタイムを手動更新する設定をすれば少なくともエラーは回避。
Tips4 Infrastructure as Code
[Tips 4] Infrastructure as Code IaCで作る際、どの方式が良いか? Cloudformation(Terraform) or AWS Serverless
Application Model ? > ポイント: LambdaアプリケーションはCI/CDで問題ないが、リソースなどの設定は抽象度が低い方がいいか or 高い方がいいか
[Tips 4] Infrastructure as Code AWS Serverless Application Modelを利用する場合 抽象度の高い
AWS Serverless Application Model(以下SAM) で作成した方がコード の記述量は少なくシンプルに作成することは可能。しかし、以下の場合のような[Tips1] のようなケースであるなら控えた方が良いかも。。。 - Lambdaバージョンの明示的指定 - 複数ステージ・複数エイリアスの管理 → SAMでは複数のエイリアス, バージョン管理は難しい 元ネタ: https://qiita.com/atw0_0w/items/7d5cc6abd59f0f62a6bd https://qiita.com/atw0_0w/items/1fd41907e54db0f1aef7
[Tips 4] Infrastructure as Code Cloudformation(Terraform) を利用する場合 抽象度が低いため AWS SAM
での課題は解消できる。 - Lambdaバージョンの明示的指定 - 複数ステージ・複数エイリアスの管理 しかし、パラメータの記載量が多くなり、管理が大変。 そもそもSAMもCloudformation(Cfn)も前のLambdaバージョンにロールバックできな い。。 → Lambrollを使って更新すればロールバックもできるし、簡単にデプロイできる(個人 的おすすめ⭐) https://github.com/fujiwara/lambroll
まとめ
- API Gateway にて複数のステージを使用する場合、「${stageVariables.変数名}」 でAPI GatewayステージとLambdaエイリアスを関連づける。 - ローカルでのLambda関数の検証なら「https://gallery.ecr.aws/lambda 」を 参照。
- 複数の関数で利用するのなら、Lambda Layerを使用する。 但しパッケージの依存関係には要注意。 - 要件を洗い出して適切なIaCツールを選択する。 まとめ
ご清聴ありがとうございました