You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems it's not possible to define authorization (IAM or Custom) on the implicit API created as a lambda event source. And it looks like AWS::Serverless::Api doesn't support it either? Is there any plan to add this feature?
I think this can be done through the Swagger template, just add the following sections, the first one either at the top level of the file, or for individual resources:
Also if you want a custom authorizer, try configuring it via the Console, then export the Swagger file with AWS extensions. The relevant sections will be in that file.
I have Authorization working by specifying it in Swagger.
The tricky part is that it's necessary to explicitly permit it to be invoked by API Gateway. I used:
I think issue seem to be replacing dynamically generated lambda function name in swagger.yml file
uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:*********78:function:${stageVariables.LambdaFunctionName}/invocations
Works fine if we replace generated function name manually .
Now it stopped working. Using the API Gateway Authorizers console test:
Execution log for request test-request
Fri Dec 09 07:06:27 UTC 2016 : Starting authorizer: h2ur54 for request: test-request
Fri Dec 09 07:06:27 UTC 2016 : Incoming identity: testing123
Fri Dec 09 07:06:27 UTC 2016 : Execution failed due to an internal error
Fri Dec 09 07:06:27 UTC 2016 : Internal server error
When I type in the actual function name in the box and confirm giving the permissions, it works.
@sanathkr I have enabled iam auth on my resource but it doesn't seem to enable auth on the stage, which makes the api still public accessible. What am I doing wrong?
so ProviderARNs is basically the arn of the userpool.
The only trick is the RestApiId, which is "generated" when transforming serverless function to cloudformation. I guess it will be always ServerlessRestApi.
Hope it helps someone.
edit: forum motor messes up the "code" section I don't know why... but it json, so you can copy... :/
edit2: because I lame, that's why. Fixed.
Reacted by Danny McPherson, Yves M., Dewayne and Edward Foyle
at least that's the export, but I can't seem to get it to work when deploying. Also noted that sam/cloudformation completely removed the APIGW Authorizer if I updated the inline swagger.
Not sure if this is a new bug, or I should re-open this one.
Activity
dinvlad commentedon Nov 26, 2016
I think this can be done through the Swagger template, just add the following sections, the first one either at the top level of the file, or for individual resources:
Also if you want a custom authorizer, try configuring it via the Console, then export the Swagger file with AWS extensions. The relevant sections will be in that file.
sanathkr commentedon Nov 30, 2016
Checkout /examples/2016-10-31/api_swagger_cors for example on how to use Swagger with SAM API
mparaz commentedon Dec 7, 2016
I have Authorization working by specifying it in Swagger.
The tricky part is that it's necessary to explicitly permit it to be invoked by API Gateway. I used:
When I add an event to the authorizer function, to let SAM automatically creates the Permission, it looks like the permission isn't granted. I did:
But when I try this, in CloudWatch I see
Invalid permissions on Lambda function.I do see the permission created in CloudFormation.
beknal commentedon Dec 8, 2016
I think issue seem to be replacing dynamically generated lambda function name in swagger.yml file
uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:*********78:function:${stageVariables.LambdaFunctionName}/invocations
Works fine if we replace generated function name manually .
mparaz commentedon Dec 9, 2016
Now it stopped working. Using the API Gateway Authorizers console test:
Execution log for request test-request
Fri Dec 09 07:06:27 UTC 2016 : Starting authorizer: h2ur54 for request: test-request
Fri Dec 09 07:06:27 UTC 2016 : Incoming identity: testing123
Fri Dec 09 07:06:27 UTC 2016 : Execution failed due to an internal error
Fri Dec 09 07:06:27 UTC 2016 : Internal server error
When I type in the actual function name in the box and confirm giving the permissions, it works.
deathbob commentedon Dec 14, 2016
@sanathkr I have enabled iam auth on my resource but it doesn't seem to enable auth on the stage, which makes the api still public accessible. What am I doing wrong?
deathbob commentedon Dec 14, 2016
Ah got it, as @dinvlad stated above. Not well documented anywhere I could find.
dinvlad commentedon Dec 16, 2016
@deathbob, these are from the docs at http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html#api-gateway-swagger-extensions-authtype and http://swagger.io/specification/#securityRequirementObject
dinvlad commentedon Dec 16, 2016
Btw
security: - sigv4: []can be enabled globally by specifying it at the root of the document, if that's what you'd like: http://swagger.io/specification/#swaggerObjectsanathkr commentedon Jan 3, 2017
Closing this in favor of #49 as a feature request to add custom authorizers to implicit APIs
marczis commentedon Mar 20, 2018
With cognito user pool I managed to use it like this: (no swagger here)
so ProviderARNs is basically the arn of the userpool.
The only trick is the RestApiId, which is "generated" when transforming serverless function to cloudformation. I guess it will be always ServerlessRestApi.
Hope it helps someone.
edit: forum motor messes up the "code" section I don't know why... but it json, so you can copy... :/
edit2: because I lame, that's why. Fixed.
marczis commentedon Mar 26, 2018
Alto I hit the next wall, I can't assign this to the methods, as the serverless function does not support authorizer ? Or do I miss something here ?
gergnz commentedon Apr 21, 2018
It seems you can reference your Authorizer @marczis in swagger e.g.:
at least that's the export, but I can't seem to get it to work when deploying. Also noted that sam/cloudformation completely removed the APIGW Authorizer if I updated the inline swagger.
Not sure if this is a new bug, or I should re-open this one.
gergnz commentedon Apr 21, 2018
Spoke too soon: remove the Cloudformation, add it to the swagger resolves my issues:
sparrowt commentedon Oct 31, 2018
See #546 which recently added support for
Authproperty on explicit/implicit Api resources, (see alsoapi_lambda_*_authexamples here https://github.com/awslabs/serverless-application-model/tree/develop/examples/2016-10-31/)