ApiGateway Stage not recognises new lambda function on update when using OpenAPI definition

0

Hi,

Im using Cloudformation to create my REST API (AWS::ApiGateway::RestApi) and defining the API itself using OpenAPI and adding it to the REST API with the BodyS3Location. I noticed if I set up a new endpoint in the OpenAPI yaml definition and update the stack the new endpoint will be added to the "Resources" but not to the stage. So currently if I have to add a new function to my API my only option is to recreate the whole API. Im pretty sure that I'm missing something but cannot figure out what, I cannot find any similar examples.

The corresponding part of my template:

Api:
    Type: AWS::ApiGateway::RestApi
    Properties:
      EndpointConfiguration:
        Types:
        - REGIONAL
      BodyS3Location: 
        Bucket: !Ref OpenApiBucket
        Key: !Ref OpenApiDefinitionPath

  ApiDeployment:
    Type: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref Api

  ApiStage:
    Type: AWS::ApiGateway::Stage
    Properties: 
      MethodSettings:
        - DataTraceEnabled: true
          HttpMethod: "*"
          LoggingLevel: INFO
          ResourcePath: "/*"
          MetricsEnabled: true
      DeploymentId: !Ref ApiDeployment
      RestApiId: !Ref Api
      StageName: prod
      Variables:
        MyNewLambaFunctionARN: !Ref NewLambaFunctionARN

And my OpenAPI definitions are looking like this:

paths:
  /v1/mynewendpoint:
    ...
    post:
      x-amazon-apigateway-request-validator: all
      x-amazon-apigateway-integration:
        type: AWS_PROXY
        httpMethod: post
        uri: ${stageVariables.MyNewLambaFunctionARN}
      requestBody:
        content:
          application/json:
            schema:
              ....
      responses:
        ...

For the updates I upload the OpenApi definition with a new key to the bucket, and the call an update-stack operation using the key as a parameter. After the update is using the console I can see the new method in the API's "Resources" tab but it will be not included under the "Stages" and the API will respond with an error message when I try to execute the request towards this endpoint.

What am I missing here?

Thanks in advance!

Peter

3 Answers
0

Try adding StageName: prod to the ApiDeployment section.

profile pictureAWS
EXPERT
Uri
answered 2 years ago
0

Hi

Thank you for you answer!

So I modified my 'AWS::ApiGateway::Deployment' to this:

  ApiDeployment:
    Type: AWS::ApiGateway::Deployment
    Properties:
      RestApiId: !Ref Api
      StageName: prod

But now during the update I get this error when CloudFormation tries to update the Deployment:

Resource handler returned message: "null" (RequestToken: <TOKEN>, HandlerErrorCode: InternalFailure)

As it was not too descriptive I tried to recreate the whole stack, there I got this more verbose error message when it tries to create the Deployment:

Resource handler returned message: "Stage already exists (Service: ApiGateway, Status Code: 409, Request ID: <REQUEST_ID>, Extended Request ID: null)" (RequestToken: <TOKEN>, HandlerErrorCode: AlreadyExists)

I tried to remove the 'StageName: prod' from the AWS::ApiGateway::Stage definition, but the simple update was failing that way too, so I recreated the whole stack again. This resulted that now I have two stages (I kinda expected that) but on update none of the two will be updated with the new enpoint

pettair
answered 2 years ago
0

Do anyone has any idea how to solve this?

Or maybe this is something that is not supported by the API Gateway?

pettair
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions