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
Amplifyで始めるサーバレス開発/serverless-development-start...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
MURAKAMI Masahiko
November 30, 2020
Programming
1.5k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Amplifyで始めるサーバレス開発/serverless-development-starting-with-amplify
MURAKAMI Masahiko
November 30, 2020
More Decks by MURAKAMI Masahiko
See All by MURAKAMI Masahiko
AmplifyHostingConstructからSSRフレームワークのためのホスティング設計を考察する/amplify-hosting-construct
fossamagna
1
580
AWS Blocks を触ってみた/first-tach-aws-blocks
fossamagna
2
250
AWS Amplifyをもっと便利に使うための取り組み/amplify-tools-and-contributions
fossamagna
1
190
Amazon Verified Permissions実践入門 〜Cedar活用とAppSync導入事例/Practical Introduction to Amazon Verified Permissions
fossamagna
2
480
Amplify Gen2から知るAWS CDK Toolkit Libraryの使い方/How to use the AWS CDK Toolkit Library as known from Amplify Gen2
fossamagna
1
1k
AWS Amplify Gen2向けのVSCode拡張を作って公開してみた話/lts-techday-2024
fossamagna
0
80
CDKアプリとしてのAmplify Gen2 - @aws-amplify/backendのアーキテクチャにみるCDKベストプラクティス -
fossamagna
3
3.8k
Amplify Gen2の 新機能と実践的な使用例 AWS Amplify Gen 2 Festival in Japan/New features and practical use cases in Amplify Gen2
fossamagna
0
890
Amplify Gen2を 拡張してみよう JAWS-UG北陸新幹線 ( 福井開催 ) 2024-04-06/Let's extend Amplify Gen2
fossamagna
0
1.1k
Other Decks in Programming
See All in Programming
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
Workers Cache を知る
syumai
0
350
最近”作らせてる” ローカルAIアプリの話
akit37
0
440
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
200
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
150
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
140
mrbgem 三角測量 開発
ogom
0
230
速習iPhone Duo対応
yuukiw00w
2
980
setup-vp GitLab対応の裏側
naokihaba
0
160
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
SREの越境 / SRE Collaboration
y0hgi
2
300
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
900
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
450
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
580
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
620
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
260
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
560
Transcript
Amplifyで始める サーバレス開発 ESM MEETUP!! 2020-11-27 村上雅彦
村上雅彦 a.k.a @fossamagna
Amplifyとは
Amplifyとは “スケールするモバイルアプリ およびウェブアプリを最速で 構築する方法”
Amplifyの構成 CLI:Amplifyでアプリを構築するためのツール チェーン Cloud Services:アプリのバックエンド Framework:モバイル、Web向けの各SDK Developer Tools:CI/CD, ホスティング、モバイ ルデバイスのテスト環境
Amplifyのはじめ方 1. フロントエンドのプロジェクト作成 2. Amplify CLIでクラウドサービス(バックエンドリソース)を追加 3. Amplify CLIでクラウドに反映 4.
フロンドエンドからクラウドサービスを利用するコードを追加
Amplifyのはじめ方 (ストレージとしてS3を追加する場合) $ npx vue create my-project # Vue.jsのプロジェクト作成 $
amplify init # Amplifyプロジェクトの初期化 $ amplify storage add # ストレージを追加 $ amplify push # 追加したリソースをクラウドに反映
Amplifyのはじめ方 (Vue.jsで画像をS3にアップロードする場合) <template> <input type="file" accept="image/png" @change="upload" /> </template> <script
lang="ts"> import { defineComponent } from 'vue'; import { Storage } from 'aws-amplify'; export default defineComponent({ setup() { const upload = async (e: Event) => { const input = e.target as HTMLInputElement; const file = input && input.files ? input.files[0] : null; if (!file) return; const result = await Storage.put(file.name, file); # S3にアップロード console.log(result); }; return { upload } } }); </script>
Amplifyのカテゴリー • auth (Amazon Cognito) • storage (Amazon S3 &
Amazon DynamoDB) • function (AWS Lambda) • api (AWS AppSync & Amazon API Gateway) • analytics (Amazon Pinpoint) • hosting (Amazon S3 and Amazon CloudFront distribution) • notifications (Amazon Pinpoint) • interactions (Amazon Lex) • predictions (Amazon Rekognition, Amazon Textract, Amazon Translate, Amazon Polly, Amazon Transcribe, Amazon Comprehend, and Amazon SageMaker)
awesome list • dabit3/awesome-aws-amplify: Curated list of AWS Amplify Resources
• watilde/awesome-aws-amplify-ja: 日本語で書かれているAWS Amplifyのツール、チュートリアル、記事などのリンク集
Amplifyのカスタマイズ • Amplifyは多くの機能を提供している • 活発に開発されていて頻繁に新機能追加もある • だたし、自分の要件に100%あうとはかぎらない • 足りない部分はカスタマイズできるようになっている
Amplifyのカスタマイズ方法 • 既存カテゴリーのテンプレート編集 • カスタムCloudFormationスタックの追加 • プラグイン
既存カテゴリーのテンプレート編集 (Lambdaに環境変数を渡す場合) { "Parameters": { "RoleArn": { "Type": "String", "Default":
"<default role ARN>" } } … "Resources": { "LambdaFunction": { "Type": "AWS::Lambda::Function", "Properties": { "Environment": { "RoleArn": { "Ref": "RoleArn" } } } } } } { "EndpointURL": "<role ARN override>" } parameters.json lambda-template.json
カスタムCloudFormationスタックの追加 1. CloudFormationテンプレートファイルの追加する 2. amplify/backend/backend-config.jsonの編集する 3. CLIに追加したリソースを認識させる
カスタムCloudFormationスタックの追加 (CloudFront署名付きURLで画像共有する事例) • S3にアップロードされたファイル に対してCloudFrontの署名付き URLを発行 • S3バケット、LambdaはCLIで生 成したリソースを利用
CloudFormationテンプレートファイルの追加 { "AWSTemplateFormatVersion": "2010-09-09", "Description": "Private content resource stack creation
using Amplify CLI", "Parameters": { "storageMediaContentBucketName": { "Type": "String", "Default": "storageMediaContentBucketName" }, }, "Resources": { "PrivteContentCloudFrontDistribution": { "Type" : "AWS::CloudFront::Distribution", "DependsOn" : [ "OriginAccessIdentity" ], …. } } amplify/backend/<category>/<resource-name>/<cloudformation-template.json/yml>として配置する
amplify/backend/backend-config.jsonの編集 { "privatecontent": { "usercontent": { "service": "CloudFront", "providerPlugin": "awscloudformation",
"dependsOn": [ { "category": "storage", "resourceName": "MediaContent", "attributes": [ "BucketName" ] } ] } }, "storage": { "MediaContent": { "service": "S3", "providerPlugin": “awscloudformation" } }
CLIに追加したリソースを認識させる amplify env checkout <current-env-name> を実行して追加したリソー スをCLIに認識させる
Amplify CLIプラグイン • Amplify CLIはプラグインとして構成されている • プラグインには4つのタイプがある ◦ category ◦
provider ◦ frontend ◦ util
Amplify CLIプラグインの作成 • プラグインの雛形を生成するコマンドが用意されてる ◦ amplify plugin init ◦ プラグインの名前やタイプなどいくつかの質問に答えると雛形コード
が生成される
Amplify CLIプラグインの構成 プラグインのディレクトリ構成 |_my-amplify-plugin/ |_commands/ # サブコマンド | |_help.js |
|_version.js | |_event-handlers/ # プラグインライフサイクルイベントのハンドラ | |_handle-PostPush.js | |_handle-PrePush.js | |_amplify-plugin.json # プラグインのメタ情報 |_index.js # プラグインエントリーポイント |_package.json
Amplify CLIプラグインの実装例 (CloudFront署名付きURLで画像共有する事例) • CloudFrontを構成するためのプ ラグイン • タイプはcategory • カスタムCloudFormationスタック
のテンプレート作成、 backend-config.jsonの編集が プラグインの仕事
Amplify CLIプラグイン実装のヒント • https://github.com/aws-amplify/amplify-cliのソースが実装の参考 になる • サードパーティプラグインのソースも参考になる • amplify-cli/packages/amplify-cli/src/extensions/amplify-help ers
配下にはプラグインを実装するのに有用なメソッドがそろっている
Amplify CLIのカスタマイズのまとめ • カスタムCloudFormationスタック ◦ 本来、追加したいCloudFormationスタックとbackend-config.jsonの編集 のみでカスタマイズできる • プラグイン ◦
複数のリソースを追加するような場合は作業が楽で間違いを起こしにくい。汎 用的なら他プロジェクトでも使える(OSSにしたりもできる) ◦ amplify cliのライフサイクルに合わせて実行したいならプラグイン!