Reputation: 684
I get the following error when trying to deploy lambda and API gateway configuration
"malformed integration at path /profile/v1. (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException"
What can cause this error and how can it be resolved.
swagger: '2.0'
info:
version: v1
title: ProfileAPI
paths:
"/profile/v1":
get:
tags:
- Values
operationId: ProfileV1Get
consumes: []
produces:
- text/plain
- application/json
- text/json
parameters: []
responses:
'200':
description: Success
schema:
type: array
items:
type: string
x-amazon-apigateway-integration:
httpMethod: post
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ProfileFunction.Arn}/invocations
definitions: {}
Upvotes: 2
Views: 1386
Reputation: 176
Got a final working setup working with AWS Support that y'all might be interested in:
When we reference the cloudformation resource details in the external swagger template, we do not get the resource details and hence receive the above error. For example: “ Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations “ will not work when you try to create API gateway integration endpoint uri in swagger definition using resource : "LambdaFunction.Arn” (which is the CloudFormation resource).
In order to resolve these issues, I made the below changes in the cloudformation template:
To reference the swagger file in the cloudformation template, I uploaded the swagger template in the s3 bucket and then used the below definition. I used :
ZazzoAPI:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Variables:
LambdaFunctionName: !Ref LambdaFunction
#Configure API settings and options
MethodSettings: [{
LoggingLevel: "INFO",
MetricsEnabled: True ,
HttpMethod: "GET",
ResourcePath: "/"
}]
DefinitionBody:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: "s3://s3.code-deploy/swagger_SAM.yaml"
The AWS::Include transform lets you create a reference to a transform snippet in an Amazon S3 bucket. It allows to reference the cloudformation resource details in an external swagger file. You can refer to the documentation at [1] for more details regarding "AWS::Include” Transform.
I then checked the swagger template and could see that you are using shorthand notations for specifying the integration uri. However, "AWS::Include” does not currently support using shorthand notations for YAML snippets as mentioned in the documentation [2]. Therefore, I used the intrinsic function "Fn::Sub" and was able to reference the required cloudformation parameters in the swagger template.
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations”
uri:
Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations"
Upvotes: 1