我正在尝试在.Net Core Web API应用程序上设置一个已经存在的授权者功能。 当我使用纯aws lambda nodejs时,.yml文件来完成它,如下所示:
custom:
defaultStage: test
currentStage: ${opt:stage, self:custom.defaultStage}
defaultRegion: us-east-1
currentRegion: ${opt:region, self:custom.defaultRegion}
**defaultAuthorizer**: us-east-1:xxxxxxxx:function:TypeToken-test-Authorizer
**currentAuthorizer**: ${opt:authorizer, self:custom.defaultAuthorizer}
provider:
name: aws
runtime: nodejs6.10
stage: ${self:custom.currentStage}
profile: ${opt:profile, "default"}
region: ${self:custom.currentRegion}
functions:
MyFunctionName:
handler: handlerTestAPI.myFunctionName
events:
- http:
path: myFunctionName
method: post
cors: true
integration: lambda
**authorizer:**
arn: arn:aws:lambda:${self:custom.currentAuthorizer}
resultTtlInSeconds: 0
identitySource: method.request.header.Authorization
type: token
在这种情况下,ASP.NET Core App serverless.template 文件与此类似:
"Resources" : {
"AspNetCoreFunction" : {
"Type" : "AWS::Serverless::Function",
"Properties": {
"Handler": "Test.API::Project.API.LambdaEntryPoint::FunctionHandlerAsync",
"Runtime": "dotnetcore2.1",
"CodeUri": "",
"MemorySize": 256,
"Timeout": 30,
"Role": null,
"Policies": [ "AWSLambdaFullAccess" ],
"Environment" : {
"Variables" : {
"TestTable" : { "Fn::If" : ["CreateProjectTable", {"Ref":"ProjectTable"}, { "Ref" : "ProjectTableName" } ] }
}
},
"Events": {
"PutResource": {
"Type": "Api",
"Properties": {
"Path": "/{proxy+}",
"Method": "ANY"
}
}
}
}
}
我已经搜索了使用serverless.template文件在.net核心无服务器功能之上设置了现有授权者的模板,但是还没有找到。
感谢您的反馈。
答案 0 :(得分:2)
我认为这是一项广泛要求的功能,但until a few day之前还不支持
github页面现已更新
https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
现在您可以使用AUTH属性
Auth configuration for this specific Api+Path+Method. Useful for overriding the API's DefaultAuthorizer or setting auth config on an individual path when no DefaultAuthorizer is specified.
默认模板生成隐式API网关。要设置anthorizer,您可能需要create an explicit API gateway
此外,他们的Github页面上还有一个example