Giter Club home page Giter Club logo

Comments (7)

sanathkr avatar sanathkr commented on September 13, 2024 1

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.

collinforrester avatar collinforrester commented on September 13, 2024

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.

sanathkr avatar sanathkr commented on September 13, 2024

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.

collinforrester avatar collinforrester commented on September 13, 2024

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.

collinforrester avatar collinforrester commented on September 13, 2024

I'm good to go now.

For future reference for anyone that stumbles onto this:

  1. like sanathkr said, use stageVariables in the swagger file, and !Ref cloudformation parameters in the SAM file
  2. Remove the protocol http:// and /{proxy} from the variable and hard code those into the swagger template.

Thanks!

from serverless-application-model.

saravanan-devops avatar saravanan-devops commented on September 13, 2024

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.

brettstack avatar brettstack commented on September 13, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.