![](/img/trans.png)
[英]How to integrate a new authorizer for AWS API Gateway through “Serverless” framework?
[英]How to get reference to aws api gateway in serverless framework
provider:
name: aws
runtime: nodejs14.x
functions:
hello:
handler: handler.hello
events:
- httpApi:
path: /
method: get
RestApiId:
Ref: TestApi // How to get reference of AWS::Serverless::Api i.e. TestApi here
resources:
Resources:
authFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: .
Handler: handler.hello
TestApi:
DependsOn: AuthFunction
Type: AWS::Serverless::Api
Properties:
StageName: dev
Auth:
DefaultAuthorizer: LambdaRequestAuthorizer
Authorizers:
LambdaRequestAuthorizer:
FunctionPayloadType: REQUEST
FunctionArn: !GetAtt AuthFunction.Arn
得到錯誤:
Configuration error at 'functions.hello': unrecognized property 'RestApiId'
讓我們首先澄清一些事情。
httpApi
事件使用的是 HTTP API,而不是來自 AWS Api Gateway 的 REST API。
您可以通過以下方式指定外部創建的 HTTP API:
provider:
httpApi:
id: <your http api reference>
如果您想使用 REST API,那么您需要使用http
事件類型並將其設置如下:
provider:
apiGateway:
restApiId: <your rest api reference>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.