Comments (7)
You should use CloudFormation parameters to customize your inputs. You will have one SAM file but customize each stack by specifying different parameters
from serverless-application-model.
So to give a little more insight to what I have so far so you can point me in the right direction:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
InternalAPIUrl:
Type: String
Description: Internal API URL
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: api.swagger.yaml
And inside of api.swagger.yaml:
# removed
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
uri: !Ref InternalAPIUrl
requestParameters:
integration.request.path.proxy: "method.request.path.proxy"
passthroughBehavior: "when_no_match"
httpMethod: "ANY"
cacheNamespace: "aabbcc"
cacheKeyParameters:
- "method.request.path.proxy"
type: "http_proxy"
# removed
When I executed the deploy
command (after standard package
command), I did aws cloudformation deploy --parameter-overrides InternalAPIUrl=http://domain.com/{proxy} --template-file ./service.cfn.yaml --stack-name api-gateway --capabilities CAPABILITY_IAM --region us-east-1
.
Where am I going wrong with this?
The error I got was related to an invalid URI for the proxy endpoint I'm guessing because I didn't get the variable resolved properly.
from serverless-application-model.
You cannot have CloudFormation !Ref directly inside swagger. You need to use StageVariables like this:
https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/api_swagger_cors/template.yaml#L11. You will !Ref InternalAPIUrl
on the Variable
https://github.com/awslabs/serverless-application-model/blob/master/examples/2016-10-31/api_swagger_cors/swagger.yaml#L23. Instead of Lambda function ARN, you will simply use refer your to your stage variable
from serverless-application-model.
Ok thanks for the quick response. I think I'm getting close, but it still seems like I'm missing a piece. Here are the two things I tried:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: api.swagger.yaml
StageName: dev
Variables:
InternalAPIUrl: !Ref InternalAPIUrl
In my swagger file:
# ...
uri: ${stageVariables.InternalAPIUrl}/{proxy}
# ...
When I tried to deploy it I got this error:
aws cloudformation deploy --parameter-overrides InternalAPIUrl=http://domain.com --template-file ./service.cfn.yaml --stack-name api-gateway-main --capabilities CAPABILITY_IAM --region us-east-1
Waiting for changeset to be created..
Failed to create the changeset: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Circular dependency between resources: [ApiGatewayApidevStage]
So I tried to simplify it some and remove the cloudformation parameter part and just use the stage variables first... I got a little further.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
DefinitionUri: api.swagger.yaml
StageName: dev
Variables:
InternalAPIUrl: http://domain.com
with the same swagger file got the changeset created but failed during the deploy process with this:
Errors found during import: Unable to put integration on 'ANY' for resource at path '/{proxy+}': Invalid HTTP endpoint encoding detected for URI
I tried doing the same via the console, adding ${stageVariables.InternalAPIUrl}
for the proxy HTTP endpoint and got invalid uri
error in the UI.
from serverless-application-model.
I'm good to go now.
For future reference for anyone that stumbles onto this:
- like sanathkr said, use
stageVariables
in the swagger file, and !Ref cloudformation parameters in the SAM file - Remove the protocol
http://
and/{proxy}
from the variable and hard code those into the swagger template.
Thanks!
from serverless-application-model.
Hi Guys,
Currently we have separate AWS accounts for each environment (dev,st,sit,pt,prod). And we are managing the SAM/ Swagger files for each environment. Let me know if there's any option to promote api gateway and lambda to higher environments. So that our manual editing work will be reduced.
Regards
Saravanan.C
[email protected]
from serverless-application-model.
@saravanan-devops have you seen this? https://aws.amazon.com/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/
from serverless-application-model.
Related Issues (20)
- Can't reset BinaryMediaTypes to a default value for API Gateway REST API HOT 2
- AWS::Serverless::Api auto deploys API when a resource is being added HOT 4
- Environment variables not updated HOT 5
- Bug: Using a Ref in StageName is Not Working Properly - Template.yaml HOT 4
- !If not working on Serverless:Function handler HOT 5
- how to configure KMSVerifyPolicy and KMSSignPolicy HOT 1
- Feature request: Git sync HOT 4
- Security: default permission allow any service to invoke a lambda function HOT 3
- Several tests fail with Pydantic 1.10.15 (latest 1.x) HOT 6
- (New Connector Profile) AWS Batch HOT 1
- EventInvokeConfig does not appear in processed template when following the spec HOT 3
- (New Connector Profile) AWS::ApiGateway::RestApi > AWS::Serverless::StateMachine HOT 1
- Bug: Lambda function (with alias) doesn't create a new version after its layer is updated, even if `AutoPublishAliasAllProperties` is set to `true` HOT 7
- Several tests fail with Pydantic 1.10.17 (latest 1.x) HOT 5
- Bug: No new Lambda Versions are deployed with Lambda configurations changes HOT 6
- Event sources do not invoke versioned state machines by their alias HOT 4
- Lambda layer code not updated in Lambda function during `sam sync` HOT 1
- SQS:*Batch permissions aren't vaild permissions HOT 2
- Can't use ForEach intrinsic function to define resources HOT 6
- Set Pydantic 2.* as possible dependency HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-application-model.