Share
Embed
サーバーレスクイックスタート: 手を動かしながら学ぶサーバーレスはじめの一歩 / Serverless Quick Start hands-on
"速習サーバーレス" 的なハンズオンです。
ソースコードはこちら → https://github.com/ketancho/aws-serverless-quick-start-hands-on
■ 2020/02/19 JAWS−UG 初心者支部 #24
■ 2020/04/28 JAWS-UG 初心者支部&千葉支部 #26
にて実施しています。資料だけでもハンズオンはご実施いただけますが、登壇させていただくことも可能ですので @ketancho までお声がけください:)
ketancho
April 28, 2020
Transcript
94 slides
-
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. © 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. $' # (" %!'51+8 Solutions Architect <7 / / Kei Kanazawa / @ketancho [2020/04/26 JAWS−UG ,294;=.:4;] ( (&(> 3- 0( (& )6 pdf http://bit.ly/serverless-quick-start src http://bit.ly/serverless-quick-start-src #jawsug_bgnr #jawsugchiba * ! -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. =2;+ ❏ .- @9 / Kei Kanazawa ❏ &)% %$")#') ❏ <8 (17, 5?*65?!&A:' (AWS 3>4 0 ❏ 0 AWS) AWS Lambda @ketancho -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § 90 ! § % ' &$ § Next Action # ! " ! -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § `pZPp A AWS MQOp^J/<>+H3? § `pZPp>'- AWS UqbYA&A+H IAM kqVq>oSNp6=2;5, § `pZPp>B AWS AUqbYA )m\qYAJ 6C8* #J.H3?E+G)9A4 18H3?J+F07D42;5,* § " Am\qYA! E)(A>4 J/%,6C8 § Chrome or Firefox >h_qXjp^Tp\qn@MR[Y6=2;5, § Python eoSliATcq&gqY^@B)Np]p^$I@4 2;5, -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. .- " “##!” %9%' 9 ""6: AWS Lambda -→314 ""7: 14 Web API & ""8: +(5 + 14 "& “$* )0,/” 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. .- " “##!” %9%' 9 ! ""6: AWS Lambda -→314 ""7: 14 Web API & ""8: +(5 + 14 "& “$* )0,/” 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. M 3;( -A >?C _ @ JX `! ! 4:&/Q 8=#= 29<! 4=1= 3;- ,=' ZY 39 \S PV +$- 8=#= +$- FRL^ =+ )6ZY "=0= %*-*3 5.: ZH K N]WET "=0=G %79+1*) I PV[D _ %79+ 1*)IB __ \SUOI @`! -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. “ ” “ ” -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. “ ” -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. .- " “##!” %9%' 9 ""6: AWS Lambda -→314 ! ""7: 14 Web API & ""8: +(5 + 14 "& “$* )0,/” 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. .- " “##!” %9%' 9 ""6: AWS Lambda -→314 ! ""7: 14 Web API & ""8: +(5 + 14 "& “$* )0,/” 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Compute L L -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § '' %"&/75 %#!-; ' § '-; 3+'$& Lambda *-1 =6: 0 '2 >( § /<)8 $ ' AWS Lambda 4. ?,9@AWS Lambda /< https://aws.amazon.com/jp/lambda/pricing/ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda " 2 % '&Lambda Function ”Hello World” ! (&Lambda Function Amazon Translate $ ')AWS Lambda → # AWS Lambda Amazon Translate ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda " 2 % '&Lambda Function ”Hello World” ! ! (&Lambda Function Amazon Translate $ ')AWS Lambda → # AWS Lambda ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § : § : !: IAM & ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § lambda Lambda : AWS Lambda ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § !$ ( *")& “( ” ' #% ! + ,: Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § OK : Lambda Function § : translate-function § : Python 3.8 § ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § 1($&# &&8 § 776 ‘Hello from Lambda!’ )9* -5 § .' ,0 !%";/4 ,02 :!< %%=: Lambda Function +3 ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § ,: Lambda Function !& !& event # % *($ " ')+ ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § [,5!] ”$$#%” ' AWS % / *4 event 20 !#% => “Hello World” § $. Test )+ § -& (3 $" $$7: Lambda Function 16 ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. “Amazon API Gateway AWS Proxy” -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § § " ! #: Lambda Function ! ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda 2 "!Lambda Function ”Hello World” #!Lambda Function Amazon Translate ! "$Hello World on AWS Lambda AWS Lambda Amazon Translate ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § Lambda Function %! $ § " &IAM %#' (: Lambda Function IAM ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § : Lambda Function IAM ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § "%$ translate TranslateFullAccess ! § &: Lambda Function IAM # ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § Lambda ! § § " # $: Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. 1: Lambda Function !& import json import boto3 def lambda_handler(event, context): translate = boto3.client('translate') input_text = '/,2' response = translate.translate_text( Text=input_text, SourceLanguageCode='ja', TargetLanguageCode='en' ) output_text = response['TranslatedText'] return { 'statusCode': 200, 'body': json.dumps({ 'output_text': output_text }) } § AWS SDK for Python (boto3) #' § “AWS SDK Python” %) " + .(- $*0boto 3 https://boto3.amazonaws.com/v1/documentation/api/ latest/reference/services/index.html https://github.com/ketancho/aws-serverless-quick-start-hands- on/blob/master/src/translate-function.py ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § ! > § ()'% OK ! input_text # $,!" +-* " .: Lambda Function & ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. .- " “##!” %9%' 9 ""6: AWS Lambda -→314 ""7: 14 Web API & ! ""8: +(5 + 14 "& “$* )0,/” 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Amazon API Gateway Amazon DynamoDB Amazon SQS (Amazon Simple Queue Service) AWS Step Functions Amazon S3 (Amazon Simple Storage Service) Amazon CloudWatch AWS X-Ray AWS Lambda -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. • )) !& $'A> API -9(A> #)) • 2?8 :.)%' API A>7F API Gateway + H@E 5/0 C-< I* • ;G,B%") J REST API 43K Amazon API Gateway =6 J1DKBlackBelt %): Amazon API Gateway https://d1.awsstatic.com/webinars/jp/pdf/services/2019051 4_AWS-Blackbelt_APIGateway.pdf -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Amazon API Gateway AWS Lambda # Web API $%!" Web API AWS Lambda Amazon Translate Amazon API Gateway GET /translate?input_text= { ‘output_text’: ‘Hello’ } ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. #: Lambda Function import json import boto3 def lambda_handler(event, context): translate = boto3.client('translate') input_text = event['queryStringParameters']['input_text'] response = translate.translate_text( Text=input_text, SourceLanguageCode="ja", TargetLanguageCode="en" ) ... § input_text " API Gateway ! > https://github.com/ketancho/aws-serverless-quick-start-hands- on/blob/master/src/translate-function-with-apigw.py ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § ”Amazon API Gateway” ,2 0- $ > */. api ! > API Gateway 1& § )# API (" API % ' 3 (+4 5: API Gateway - API % ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § &REST API $% § “#! API " ” OK ': API Gateway - API " ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § REST API § API translate-api API : API Gateway - API ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § > : API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § “ ” translate : API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § /translate > : API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § “/translate” § GET ✓ : API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § “Lambda ” ✓ “Lambda !” translate-function ": API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § “Lambda ” OK : API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § API : API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § " $ %#! dev &: API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § ! % #$ &% %" > dev ' (: API Gateway - ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § URL 87 "'- > (* #>/ § URL 6/translate?input_text=1API20 § := Web API 57 !!! URL .9@4<;3? " &,$!,A: API Gateway - %)+ ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. .- " “##!” %9%' 9 ""6: AWS Lambda -→314 ""7: 14 Web API & ""8: +(5 + 14 "& ! “$* )0,/” 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § 3 !( )"2 § 2019%11+*-1$' § #3 !(0 4!( *-1,$'5 Amazon Transcribe .& 4/5AWS Black Belt Seminar: Amazon AI Service https://aws.amazon.com/jp/blogs/news/webinar-bb-ai-service-2019/ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda Amazon Transcribe " ! #$ ! AWS Lambda Amazon Transcribe ..% ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Amazon API Gateway Amazon DynamoDB Amazon SQS (Amazon Simple Queue Service) AWS Step Functions Amazon S3 (Amazon Simple Storage Service) Amazon CloudWatch AWS X-Ray AWS Lambda -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § LF.9 : &""+--$ § 99.999999999% M+&,#,N § @A 7 3 '($)! -,MAZN>D § 6HB1J50 "+- § ? AWS -$ G; § /: %*>D ")-K3= Lambda I<4 Amazon Simple Storage Service (Amazon S3) C8 M2ENAWS Black Belt Seminar: Amazon S3/Glacier https://aws.amazon.com/jp/blogs/news/webinar-bb-amazon-s3-glacier-2019/ M2EN'($)!- -, https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/using-regions- availability-zones.html -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda Amazon Transcribe AWS Lambda Amazon Transcribe Amazon S3 Amazon S3 ♪ ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § Input Output 2 S3 § “ ” > “S3” > “S3” : S3 ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § : S3 ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § ! yyyymmdd-transcribe-input-yourname * !$ "% § # &: S3 # ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § 2 § yyyymmdd-transcribe-output-yourname § : S3 ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § AWS Lambda : > lambda > Lambda § : Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § > S3 Enter § s3-get-object-python : Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § Function : transcribe-function, Role : transcribe-function-role : Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § S3 ! input " #: Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § ✓ § : Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § IAM S3 / Transcribe '%" $ § Lambda Function & #( § ): Lambda Function ! ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § : Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § #&% S3 ! > AmazonS3FullAccess ✓' ( § #&% transcribe ! > AmazonTranscribeFullAccess ✓ § 2 $ ): Lambda Function " ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § $ § “ "(” ! “&” § #%' ): Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. ▼ !" Output #: Lambda Function import json import urllib.parse import boto3 import datetime s3 = boto3.client('s3') transcribe = boto3.client('transcribe') def lambda_handler(event, context): bucket = event['Records'][0]['s3']['bucket']['name'] key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8') try: transcribe.start_transcription_job( TranscriptionJobName= datetime.datetime.now().strftime("%Y%m%d%H%M%S") + '_Transcription', LanguageCode='en-US', Media={ 'MediaFileUri': 's3://' + bucket + '/' + key }, OutputBucketName='yyyymmdd-transcribe-output-yourname' ) except Exception as e: print(e) print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket)) raise e https://github.com/ketancho/aws-serverless-quick-start- hands-on/blob/master/src/transcribe-function.py ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § : Lambda Function ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § (" ' URL)Amazon Polly * ! # or DL % https://d1.awsstatic.com/product-marketing/Polly/HelloEnglish- Joanna.0aa7a6dc7f1de9ac48769f366c6f447f9051db57.mp3 +: $& ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § S3 mp3 ! "$ Input % S3 "$ § ! ,' & DL mp3 ! *("$ ##-: # )+ ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § $ > transcribe &' > Amazon Transcribe 2* § Transcription Jobs -3 1/4Transcribe 0. 5+ )% #$$ $ " > Transcription jobs " ##6: !# (, ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § Job Status In progress Complete Complete Name : ↓ ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § Output data location : ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § *)+! '- $(; § Json $( , results > transcripts > transcript 89=3/ 6> “transcript”: “Hello. Do you speak a foreign language? One language is never enough.” 50: 4. ! "**?: #%&* 17 2< -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda Amazon Transcribe !" AWS Lambda Amazon Transcribe Amazon S3 Amazon S3 ♪ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda Amazon Transcribe ! + %’#"$& + AWS Lambda Amazon Transcribe Amazon S3 Amazon S3 AWS Lambda Amazon Translate ♪ ✋ -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Option 1: $((A9; Web API +3 Web API 9;08?**@ Amazon DynamoDB ") # ,7 Option 2: $((B5/< %&'(+3 %&'( Amazon Comprehend =4 !# 21-6 : $(( +α Option .> -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Hands-on for Beginners ! -/ / - / - . / - . / +α -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § 90 # § '" ) (& § Next Action % # $ ! ! -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § : S3 x 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § * %# -* 0( * %# ) 1 * ,& § $ " * § * + !.'/ !.'/: S3 !. x 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § § : S3 x 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § API ✓ Actions > Delete § : API Gateway -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § > § : Lambda Function x 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § ✓ § : IAM x 2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § Job Name Delete § Delete : Transcribe Job -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. .- § “((&” /4 #%15 § '' “37 Web API” “,+8 "$'” 02 § ''9 )6(!/4 § AWS Lambda § Amazon API Gateway § Amazon S3 § Amazon Translate, Amazon Transcribe § AWS Hands-on for Beginners * ! -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. § 90 # § '" ) (& § Next Action % # $ ! ! -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved.