Questions about Deployment using SAM
Hello,
I have just successfully used SAM to deploy serverless express application(lambda + apigateway) across accounts. Couple things I have questions about:
-
I noticed that if I update my swagger file it does not deploy the changes. Is this because my swagger file s3 path and name have not changed? I am hard coding it into the template and not using the automatic uri that the package command can offer.
-
Is there a good way to enable cloud watch logs via the api resouce.
I will have lots of questions :)
Braun
There is a bug due to which your changes in Swagger file don't get redeployed. We are working on fixing it.
Enabling CloudWatch logs for APIGateway endpoint? At the moment you can't do it via SAM. Not the best idea, but you can enable it via the Console if you want - https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cloudwatch-logs/
@sanathkr Can you provide details about this bug? Is it not getting redeployed because the S3 URL is the same, or is it not getting redeployed because the name didn't change? Or is it no getting redeployed because the S3 URL AND name didn't change?
Also, how can one specify the name of the API through the SAM template? I can't see any name property generated for the Gateway resource.
And one more question. We see that through console you can create two seperate API instances with the same name. But through SAM we couldn't achieve it. Is this possible? If not, is it not because of limitation of SAM, Cloudformation, or something else?
@Fogetti First of all, Swagger S3 URL must change to trigger a re-deployment. Secondly, there is a bug in the implementation that did not trigger a redeployment even if the S3 URL changed. We are working on fixing it
If you use a swagger file, you can set the name via Title property of info field. Otherwise you can't set name via SAM.
If you create two AWS::Serverless::Api resources with same name defined in the Swagger files, you will get two API instances with same name
Thanks @sanathkr ! Much clearer now.
+1 on this. A lack of redeployment when swagger changes is creating a lot of extra work right now.
This has been fixed. Your API would be redeployed when Swagger changes.
Which version is this fix in? I did not see a commit mentioned in this bug thread?
Just use your existing SAM template. It will start working. This package maintains only the specification. No changes required here. Fix was deployed to the backing service.
Thank you for the info! Is this live in all regions supporting SAM?
Yes indeed
@sanathkr correct me if this is not a bug . If I redeploy with a change in the stage name in the swagger its actually replacing the current stage and adding the new stage. For Eg : suppose i deploy "dev" stage and then want the same code to be promoted to the "prod" stage in the same API gateway - API name, its is not happening .
^
@philipakash Yes, it will replace the stages. The recommended way with SAM is to create separate stacks for dev & prod. Your SAM file is the artifact that gets promoted from dev to prod.
@sanathkr My API definition:
DeverAPI:
Type: AWS::Serverless::Api
Properties:
StageName: v1
CacheClusterSize: !Sub ${CacheClusterSize}
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location: !Sub s3://${ArtifactsBucket}/swagger/${SwaggerSpecificationFile}
When I'm changing ${SwaggerSpecificationFile} I'm getting No updates are to be performed
I've added extra parameter ${CacheClusterSize} just to make cloudformation update the stack, but update ignores changes in swagger file location.
I can't use DefinitionUri: because I need to pass variables to swagger file.
Is there workaround for my case? I need to update API's without redeploy everything from scratch.
Thanks in advance.