I have an AWS Lambda function, to which I am trying to provide permission after successfully setting it as an Authorizer.
Basically I want to achieve the following in CloudFromation -
Following is my CloudFormation resource, which is unable to set the permission -
GWAuthPermission:
Type: "AWS::Lambda::Permission"
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt AuthTest.Arn
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGatewayRestApi}/authorizers/${AuthTest}"
ApiGatewayRestApi - is the logical Id of the Gateway
AuthTest - is the logical Id of the Custom Auth lambda function
For a Lambda authorizer of the REQUEST type, API Gateway passes request parameters to the authorizer Lambda function as part of the event object. The request parameters include headers, path parameters, query string parameters, stage variables, and some of request context variables.
Go to the API Gateway created in step “1”. Go to “Authorizers” section and click “Create New Authorizer”. Enter a “Name”, select “Type” as “Lambda”, select the Lambda function that was created in step “2” as “Lamda Function”. For the field “Token Source” enter the name “jwt_token” as below.
I was able to resolve it with the following -
Added AWS::ApiGateway::Authorizer
resource,
And referred it to AWS::Lambda::Permission
Code -
GWAuth:
Type: AWS::ApiGateway::Authorizer
Properties:
AuthorizerUri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AuthLambda.Arn}/invocations"
RestApiId: !Ref ApiGatewayRestApi
Type: "REQUEST"
IdentitySource: method.request.header.authorization
Name: custom_auth
GWAuthPermission:
Type: "AWS::Lambda::Permission"
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt AuthLambda.Arn
Principal: "apigateway.amazonaws.com"
SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGatewayRestApi}/authorizers/${GWAuth}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With