Reputation: 1259
I am trying to set an already existing authorizer function on my .Net Core Web API app. When I use purely aws lambda nodejs, the .yml file to accomplish it, looks like this:
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
For this case, the ASP.NET Core App serverless.template file is similar to this:
"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"
}
}
}
}
}
I have searched for templates where an existing authorizer is set on top of a .net core serverless function using serverless.template file, but haven't found one yet.
Thanks for the feedback.
Upvotes: 3
Views: 1506
Reputation: 5220
I think it's a widely requested feature but not supported yet until a few days ago
The github page is now updated
https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Now you can use the AUTH property
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.
The default template generate an implicit API gateway. To set anthorizer, you may need to create an explicit API gateway
Also, there is an example on their Github page
Upvotes: 2