一步一步建立第一个API + lambda application
Lambda and API gateway Java example
API gateway也可以直接invoke Step function (默认为async的startExecution API,大概80ms latency,也可以invoke stopExcution, startSyncExecution),返回值为step function run id, start time等,一定要用Post。
Post在input里用$request.body支持request payload
IAM role,需要有APIGatewayInvokeFullAccess和StepFunctionFullAccess
Logging:
默认没有log,可以到Monitor->Logging去enable
需要自己创建一个log group
format需要加入$context.error.message, $context.integrationErrorMessage,否则即使是500,也不会知道是什么错误,其他log参数
Authentication & Authorization
可以用Federate + Cognito Identity pool/Cognito user pool 来Authenticate 用户,但这多数用于真正用户。另一种方法是用Lambda Authorizer作为interceptor来做验证。
作为程序用户,可以用IAM user(非AWS resource)或者IAM role(AWS resource)来验证。
需要AmazonAPIGatewayInvokeFullAccess的permission
Frontend用不checkin的方法来本地存API key
CORS
Request有两种:simple和non simple。我的case是返回contentType=json,不是Simple所以需要CORS support。API gateway设置如下:
allow-control-allow-orgin=https://www.vtasters.com (no slash)
access-control-allow-headers=access-control-allow-origin, content-type, authorization, referer
access-control-allow-methods=POST, GET
access-control-max-age=600 (Same as Chrome)