0
votes

I am trying to provision Lambda and API Gateway using CloudFormation template and trying to invoke Lambda in one of the method, but getting issue like function arn is invalid. Please provide some resolution on this

{

"AWSTemplateFormatVersion":"2010-09-09",

"Transform":"AWS::Serverless-2016-10-31",

"Description":"Testing.",

"Parameters":{
   
},
"Conditions":{
   
},
"Resources":{
   "AspNetCoreFunction":{
      "Type":"AWS::Serverless::Function",
      "Properties":{
         "Handler":"<Handler_details>",
         "Runtime":"dotnetcore3.1",
         "CodeUri":"",
         "MemorySize":256,
         "Timeout":30,
         "Role":"$Function_Role",
         "Policies":null,
      }
   },
   "gateway":{
      "Type":"AWS::ApiGateway::RestApi",
      "Properties":{
         "Name":"Test",
         "Description":"Testing",
         "ApiKeySourceType":"HEADER",
         "EndpointConfiguration":{
            "Types":[
               "REGIONAL"
            ]
         }
      }
   },            
 
   "ApiMethod":{
      "Type":"AWS::ApiGateway::Method",
      "Properties":{
         "RestApiId":{
            "Ref":"gateway"
         },
         "HttpMethod":"ANY",
         "AuthorizationType":"NONE",
         "Integration":{
            "IntegrationHttpMethod":"POST",
            "TimeoutInMillis":29000,
            "Type":"AWS_PROXY",
            "Uri":{
               "Fn::Sub":[
                  "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations",
                  {
                     "lambdaArn":{
                        "Fn::GetAtt":[
                           "AspNetCoreFunction",
                           "Arn"
                           
                        ]
                     }
                  }
               ]
            }

         }
      }
   }

}

I have tried to use below uri, behalf above uri which is mentioned in above code, but still having same issue.

"uri": "Fn::Sub":["arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/${AspNetCoreFunction.Arn}/invocations"]

1
What exactly is the error message?Marcin
@Marcin. Thanks for your comment. Please find the ERROR. Invalid lambda function (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 9cc5af0e-f6a1-4fe4-bad4-bdb066959928; Proxy: null)kaka

1 Answers

0
votes

I think the error is not about ARN, but about API gateway not having permissions to invoke your function. You need to add something like the following:

{
  "AllowApiInvokations": {
    "Type": "AWS::Lambda::Permission",
    "Properties": {
      "Action": "lambda:InvokeFunction",
      "FunctionName": "<function-name>" ,
      "Principal": "apigateway.amazonaws.com"
    }
  }
}