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

Questions about Deployment using SAM

Open braunreyes opened this issue 9 years ago • 14 comments

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

braunreyes avatar Jan 04 '17 00:01 braunreyes

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 avatar Jan 04 '17 00:01 sanathkr

@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?

ghost avatar Jan 05 '17 12:01 ghost

@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

sanathkr avatar Jan 06 '17 19:01 sanathkr

Thanks @sanathkr ! Much clearer now.

ghost avatar Jan 09 '17 08:01 ghost

+1 on this. A lack of redeployment when swagger changes is creating a lot of extra work right now.

terodox avatar Jan 24 '17 14:01 terodox

This has been fixed. Your API would be redeployed when Swagger changes.

sanathkr avatar Feb 17 '17 22:02 sanathkr

Which version is this fix in? I did not see a commit mentioned in this bug thread?

terodox avatar Feb 21 '17 14:02 terodox

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.

sanathkr avatar Feb 21 '17 20:02 sanathkr

Thank you for the info! Is this live in all regions supporting SAM?

terodox avatar Feb 22 '17 00:02 terodox

Yes indeed

sanathkr avatar Feb 22 '17 00:02 sanathkr

@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 avatar Feb 23 '17 14:02 philipakash

^

philipakash avatar Mar 02 '17 17:03 philipakash

@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 avatar Mar 02 '17 18:03 sanathkr

@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.

mputilin avatar Oct 09 '17 13:10 mputilin