aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

Show release history and allow rollback to previous revision #1654

Open ktal90 opened 6 years ago

ktal90 commented 6 years ago

It would be very useful to be able to get the deployment history for a SAM application from the command line. Right now, a developer relies on git to track to know about the code history, but without full CI/CD, he/she does not have insight into SAM's release history. It would be extremely useful to have that that history. In the spirit of SAM, this should be readily accessible from the command line.

Additionally, it would be very useful to be able to roll back to a previous release as it was deployed previously. This is different than rolling back to a previous version of the code and redeploying. Rolling back would provide confidence that the roll back is to a prior working state as it was in the environment previously.

sanathkr commented 6 years ago

This looks really compelling. Let's see if we can hash out the details to come up a clear set of requirements and make a it a feature request :)

Can you explain your SAM usage a bit more (num Lambda functions, num repositories, frequency of deployment, num regions etc)? I know the CI/CD workflow pretty well but looks like you don't use CI/CD systems. How do you deploy to production otherwise?

christopheblin commented 6 years ago

I think I am in the same situation here

Basically, I have one sam template that I manually package + deploy after a build (I am in the early stage of the project, not any CI configured yet)

This template has a Stage parameter that is either Dev or Prod and which creates 2 different stacks.

For example,

Environment:
    Variables:
      DB_NAME:
        Fn::ImportValue: !Sub "${Stage}RDSInstanceDBName"
      DB_HOST:
        Fn::ImportValue: !Sub "${Stage}RDSInstanceAddress"

What I'd like is to be able to rollback to previous state of each stack (not necessarily function by function) if I see too much errors happening (the stack contains only lambda+API GW + cron)

I've read https://docs.aws.amazon.com/lambda/latest/dg/versioning-intro.html but I dont see how it relates to AWS SAM ...

Any idea how I can achieve that ?

michaelj-smith commented 6 years ago

@christopheblin I've just wrapped up a project where we implemented CI/CD using SAM tooling. I recommend part of the build process (whether manual or automated) include a step to publish your build artifacts into an artifact repository, using S3. Each time you package, you can package up the lambda code into a different versioned S3 folder, and then push the package.yml file itself up into the S3 bucket. That way, those S3 files can be reused to do sam deploy for any versioned artifact that exist in your S3 bucket.

For example, here's a snippet from a Jenkinsfile groovy script:

                // Determine folder structure for this release version
                base_folder     = "release-build-artifacts/${serviceName}/${releaseVersion}"
                lambda_folder  = "${base_folder}/lambda"
                cfn_folder      = "${base_folder}/cfn"

                // SAM Package
                sh "sam package --template-file ${service_name}.sam.yml \
                --s3-bucket ${s3_bucket} \
                --s3-prefix ${lambda_folder} \
                --output-template-file build/${service_name}.package.yml"
                sh "aws s3 cp build/${service_name}.package.yml s3://${s3_bucket}/${cfn_folder}"

You'll have to fill in the parameters for "${serviceName}", "${releaseVersion}", and "${s3_bucket}"

ktal90 commented 6 years ago

@michaelj-smith This makes a lot of sense, IMO -- use existing CI/CD for managing things like deploys and rollbacks. It would be great if there was some guidance in either a tutorial or in SAM's examples (https://github.com/awslabs/serverless-application-model/tree/develop/examples). This could serve as good advertisement for AWS' CI/CD tools as well 😉

keetonian commented 4 years ago

Transferring issue to SAM CLI

rainabba commented 3 years ago

I'm exploring this as well right now. My first instinct is to just use my git repo (checkout a version and deploy), but something more integrated and intentional would be appreciated.

shearn89 commented 2 years ago

Is there a flag to force a redeploy, even when CF thinks there's no changes? I just tried to use my CICD pipeline to deploy a previous tag and CF says "No changes to deploy"...