I am using AWS Custom Authorizer to secure lambda function. I am not able to use the custom authorizer because of some configurational issues.
when I tried attaching the authorizer from API Gateway Console, it is working fine. When the authorizer is attached from code, it is not giving any error. I tried checking the cloudwatch logs, the logs are not generated for lambda functions(both for authorizer and helloworld function).
Below is a sample code which I have written:
from chalice import Chalice
from chalice import CustomAuthorizer
app = Chalice(app_name='helloworld-python')
authorizer = CustomAuthorizer(
'MyCustomAuth', header='Authorization',
authorizer_uri=('arn:aws:apigateway:{region}:lambda:path/2015-03-31'
'/functions/arn:aws:lambda:{region}:{account-id}:'
'function:{function-name}/invocations'))
@app.route('/test/test_authorizer', authorizer=authorizer)
def index():
return {'hello': 'world'}
I have configured the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"execute-api:Invoke"
],
"Resource": [
"*"
]
}
]
}
I am not able to add the authorizer to the lambda function. When I fire the endpoint it is giving me following error:
End Point: https://{rest-api-id}.execute-api.{region}.amazonaws.com/dev/test/test_authorizer
Http method: GET
Error Code: 500.
Error body:
{ "message": null }
How can I achieve this. Please provide me with the proper intel.
See this issue: https://github.com/aws/chalice/issues/670#issuecomment-573637135
Alternatively, there is a workaround