serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

APIs are not getting deployed on Prod stage

Open urvi-desai opened this issue 5 years ago • 6 comments
trafficstars

Newly developed APIs are not deploying on Prod stage which can be seen in Resources tab in APIGateway

We are having server less architecture and we are using .Net core (netcoreapp2.1 framework) and AWS.

Below is a sample cloud formation template we are using.

AWSTemplateFormatVersion: 2010-09-09
Description: 'ApiGateways: APIGateway'
Transform: 'AWS::Serverless-2016-10-31'
AWS::Serverless::Api
      Properties:
      OpenApiVersion: 3.0.1
      StageName: Prod
      DefinitionUri:
        Bucket: XXX
        Key: !Ref SwaggerKey
      TracingEnabled: true
      MethodSettings:
        - DataTraceEnabled: false
          HttpMethod: '*'
          LoggingLevel: ERROR
          MetricsEnabled: true
          ResourcePath: /*
      Variables:
          API : !Ref APIFunctionName

We have only one Stage which is Prod.

After build deployment, in Cloudformation, when we turn "view processed template" on we can see resources with
"Type": "AWS::ApiGateway::RestApi", "Type": "AWS::ApiGateway::Deployment" (with APIGatewayDeployment601c725c09), "Type": "AWS::ApiGateway::Stage"

We are deploying our code through Azure devops pipeline.

Observed result: First time of deployment, all APIs are deployed on Prod stage. In second time if new APIs are added then those are not getting deployed on Prod stage.

Expected result: All APIs mentioned in the swagger should get deployed in Prod stage

urvi-desai avatar Apr 16 '20 14:04 urvi-desai

@urvi-desai is your SwaggerKey variable changing between deployments? SAM does not have permission to read your S3 files; the only way it can tell if something in that file has changed is if the name changes. Developer tools like SAM CLI and AWS CLI generate unique keys when they upload new versions of a swagger file so that processes like SAM can tell that they have changed between deployments.

keetonian avatar Apr 17 '20 22:04 keetonian

@urvi-desai is your SwaggerKey variable changing between deployments? SAM does not have permission to read your S3 files; the only way it can tell if something in that file has changed is if the name changes. Developer tools like SAM CLI and AWS CLI generate unique keys when they upload new versions of a swagger file so that processes like SAM can tell that they have changed between deployments.

Yes SwaggerKey variable value keeps changing in every build deployment. Our SwaggerKey value is like xxxapi-1.0.1.148-develop.yml. we are appending build number in swagger key value.

Swagger.yml file is on same S3 bucket where APIGateway cloud formation template is.

We are using AWS CloudFormation task in AzureDevops pipeline to deploy API gateway using cloudformation

urvi-desai avatar Apr 20 '20 08:04 urvi-desai

I looked into this some more. It appears that SAM does not resolve the SwaggerKey parameter (leaves it as-is), which means it does not know that the underlying value has changed and does not generate a new hash for the Deployment resource that it creates.

I think this can be fixed by resolving the SwaggerKey parameter (or, more specifically, any parameter) used in the DefinitionUri property. This can be done by updating how we construct the output S3 uri here: https://github.com/awslabs/serverless-application-model/blob/28884c958dfaa1c547e0f0e4ae2b8129f52e34dd/samtranslator/model/api/api_generator.py#L186

Another option is to always redeploy your API on any template deployment. Please +1 #660 if this option would also work for you to help us prioritize that feature.

keetonian avatar Apr 21 '20 22:04 keetonian

@keetonian

Thanks for providing detail information. Yes we really need #660.

As mentioned above this can be fixed by resolving the SwaggerKey parameter (or, more specifically, any parameter) used in the DefinitionUri property, Can you please elaborate more how we can resolve SwaggerKey parameter. As i mentioned above we are having dynamic value every time (xxxapi-BuildNumber-develop.yml)

I went through all comments tagged in #660. But couldn't help much to fix my issue.

It would be great if you can provide concrete solution or workaround. Sample code snippet of fix would be appreciated

urvi-desai avatar Apr 23 '20 16:04 urvi-desai

Is there any update on this issue? Please help us to resolve it as this is really one of the pain area. We need temporary fix or workaround as after each deployment we need to go and manually Deploy API from Resources tab in APIGateway

urvi-desai avatar Apr 28 '20 09:04 urvi-desai

@keetonian : Is there any update on this?

urvi-desai avatar May 14 '20 14:05 urvi-desai

If the issue is about the SwaggerKey not resolving, https://github.com/aws/serverless-application-model/issues/2533 should help (add AWS::LanguageExtensions to your Transform).

Resolving in favor of https://github.com/aws/serverless-application-model/issues/660.

hoffa avatar Nov 25 '22 20:11 hoffa