【发布时间】:2018-01-24 19:22:15
【问题描述】:
如何使用AWS SAM 创建一个使用 Cognito 用户池授权方进行授权的 API?
有AWS::ApiGateway::Authorizer。但是……
{
"Type" : "AWS::ApiGateway::Authorizer",
"Properties" : {
"AuthorizerCredentials" : String,
"AuthorizerResultTtlInSeconds" : Integer,
"AuthorizerUri" : String,
"IdentitySource" : String,
"IdentityValidationExpression" : String,
"Name" : String,
"ProviderARNs" : [ String, ... ],
"RestApiId" : String,
"Type" : String
}
}
看起来RestApiId 指的是使用这个授权者的API?但是使用 AWS SAM,我的 API 定义为
Resources:
Ec2Index:
Type: AWS::Serverless::Function
Properties:
Handler: ec2/index.handler
Runtime: nodejs6.10
CodeUri: ./src
FunctionName: 'ApiEc2IndexHandler'
Description: 'List EC2 resources'
Timeout: 30
Role: 'arn:aws:iam::598545985414:role/awsmanagement-lambda-management'
Events:
Ec2Index:
Type: Api
Properties:
Path: /ec2
Method: get
我不明白如何将它们关联在一起?
【问题讨论】:
-
如果没有 Swagger 模型(显式路线),今天这是不可能的。但是,这里正在跟踪此功能和其他功能:github.com/awslabs/serverless-application-model/issues/248。希望很快我们可以完全依赖隐式 API 定义!
-
@jiew-meng 简而言之,使用 API Authorizer Object 为您的 API 定义一个 Cognito Authorizer。然后,将您的 lambda 函数的 Auth 设置为引用此 API。您可以参考link.medium.com/X6GaTwUjWX了解更多信息。
标签: amazon-web-services amazon-cloudformation amazon-cognito