We are trying to automate the deployment of AWS lambda and API gateway using Amazon CloudFormation and Swagger. Towards this, we have created a CloudFormation template to create the Lambda and other resources required for APIGateway (including the endpoints). We would like to import the API definitions from an external swagger file so that the same CloudFormation template can be used for multiple lambdas and APIGateways. Is there a way we can refer the ARN of the lambda which has been created by the CloudFormation template in the external swagger file (being referred to in the same CloudFormation template) which holds the API definition?
Swagger content:
"x-amazon-apigateway-integration": {
"uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:TestSimpleProxy/invocations",
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy"
}
In the above integration method I need to replace the value of the uri dynamically from the cloud formation template.
My cloud formation script is as below:
"myApi":{
"Type" : "AWS::ApiGateway::RestApi",
"Properties" : {
"BodyS3Location" : S3Location of the swagger definition file,
..,
..
}
}
Is that
"x-amazon-apigateway-integration"
part of your CloudFormation template?If so, then following the example from https://blog.jayway.com/2016/09/18/introduction-swagger-cloudformation-api-gateway/, I think you can use Ref function to pass that information through.