serverless-application-model
serverless-application-model copied to clipboard
APIs are not getting deployed on Prod stage
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 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.
@urvi-desai is your
SwaggerKeyvariable 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
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
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
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
@keetonian : Is there any update on this?
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.