sumanth shetty
sumanth shetty

Reputation: 2181

Integrating API gateway with SAM template to have custom name and stage

I am trying to have a customer name given to my API gateway created through SAM template. and also restrict creating only one stage while deploying.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Specification template describing your function.
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Development
      Cors: "'*'"
  GetAllUser:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: loadeo_get_all_user
      CodeUri: code/
      Handler: get_all_user.lambda_handler
      Timeout: 5
      Runtime: python3.8
      Role: lambda_execution
      MemorySize: 128
      Events:
        GetAllUser:
          Type: Api
          Properties:
            Path: /get-all-user
            Method: get
            RestApiId:
              Ref: ApiGatewayApi

All is working fine as I want, but

  1. It is creating the API with the name of the stack (I want to give a custom name)
  2. Along with the "Development" it is also adding "stage" while deploying.

enter image description here

How I can achieve these two cases?

Upvotes: 1

Views: 1011

Answers (1)

Marcin
Marcin

Reputation: 238131

To specify Name for your ApiGatewayApi, you have to use Name property:

A name for the API Gateway RestApi resource

Thus your ApiGatewayApi would be:

  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Development
      Name: MyApiName
      Cors: "'*'"

I'm not sure I understand the second issue, thus can't comment on it right now.

As explained here you can add the following to fix the Stage issue:

Globals:
  Api:
    OpenApiVersion: 3.0.1

Upvotes: 2

Related Questions