【发布时间】:2019-04-05 21:18:48
【问题描述】:
我是 AWS Lambda 服务的新手。我创建了一个无服务器 lambda 方法并成功将其部署在 AWS 云上。
接下来,我创建了一个 Lambda 自定义 Authorizer,并为 Lambda 方法和自定义 Authorizer 配置了 API Gateway。
因为,我需要公开许多其他无服务器的 lambda 方法,因此我决定将我的 lambda 方法移动到无服务器的 .Net API 项目中。我可以将此 api 项目部署到 AWS 云,然后手动设置授权方以使用我的自定义 Authorize lambda 方法。
困难的部分是,我想通过 serverless.template 文件配置所有这些东西。
我正在努力为我的自定义授权方法获取 RESTAPIID,以及如何使用 serverless.template 文件为我的 lambda 函数设置授权。下面是我做过的配置。 另外,如何获取AuthorizerUri?
我不想硬编码任何东西。
"Resources" : {
**//How I can create this serverless function to use my custom authorizer?**
"Create" : {
"Type" : "AWS::Serverless::Function",
"Properties": {
"Handler": "Osn.Ott.Telco.Connector.UI.Web.Controllers.V10::Osn.Ott.Telco.Connector.UI.Web.Controllers.V10.SubscriptionController::Create",
"Runtime": "dotnetcore2.1",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"FunctionName" : "CreateCustomer",
"Policies": [ "AWSLambdaBasicExecutionRole" ],
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/create",
"Method": "POST"
}
}
}
}
},
"CustomAuthorizer" : {
"Type" : "AWS::ApiGateway::Authorizer",
"Properties" : {
"AuthorizerUri" : {"Fn::GetAtt" : [ "Create", "Arn"]},
"IdentitySource" : "method.request.header.Authorization,method.request.context.resourcePath, method.request.context.path",
"Name" : "CustomAuthorizer",
"Type" : "REQUEST",
**//How I can get this id?**
"RestApiId" : {"Fn::GetAtt" : [ "ServerlessRespApi", ""]}
}
}
}
【问题讨论】:
标签: amazon-web-services asp.net-core aws-lambda aws-api-gateway serverless-framework