Skip to content

Artifact Promotion across AWS Accounts #6145

Open

Description

@RaniSputnik

This is a Feature Proposal

Description

I am working on a project where we are not using API Gateway stages and instead use separate API Gateways in different AWS Accounts. What I would like to be able to do is package a single deployable (which I can currently do with serverless package), upload that deployable to an artifacts bucket in S3, then deploy that artifact from S3 without re-uploading. If I have to create a duplicate upload each time I deploy then two Lambda's running the same code in two different environments (dev and test for instance) will be pointing at two different S3 locations which makes for a confusing dev ops experience.

In summary:

  • Packaging once is important because I want to promote between environments, not rebuild.
  • Preventing re-upload is important because I want my artifacts in S3 to be immutable.
  • Deploying straight from S3 is important because then I can easily see which Lambda's are using which version of the code.

Ideas

I have a few ideas for what we might change:

1. Allow Remote URLs in Package Argument

This would allow S3 URLs to be passed to serverless deploy --package eg.

$ serverless deploy --package https://s3.eu-west-2.amazonaws.com/{bucket}/{package}.zip

The problem then is that it begs the question, what exactly does the bucket configuration in the serverless.yml file do in that instance? Is it simply ignored if the package already exists remotely? That seems wrong but I'm not sure what the correct behaviour should be.

2. Move Upload to Packaging

This would entail moving the entire upload step to packaging. I think this is the cleanest change in terms of developer ergonomics - but it is big and breaking, I wouldn't suggest we do this unless there is overwhelming support for this change.

In terms of how the API might change - I think the most sensible change would be to change the --package argument to something like --from-package or --skip-package, then the bucket settings in the serverless.yml would be used both as an upload location for post-packaging and the retrieval location when deploying the CloudFormation stack.

3. Skip Upload if Artifact Already Exists

I think deployment is skipped if the hash of the code to be deployed matches the hash of the code already present in S3. It might be a good idea to rethink this slightly and have upload skipped if the same code is already present in S3.

It would also be good to expose the S3 key that the artifact is uploaded to somewhere in the serverless.yml file - it saves having to write a plugin just to override that name.

Final Thoughts

This is a bit of a brain dump of possible approaches to this problem, but of course I am open to other suggestions! I'm relatively new to the Serverless framework so perhaps I've just misunderstood something about how it works - but it seems to me our use case is a little outside of what AWS expects from it's users (the recommendations I've seen use Lambda versions or API Gateway stages to solve the same problem we're trying to solve).

That said I do think this issue is where SAM is winning over Serverless. I think there model for package and deploy works better - I just don't want to deal with CloudFormation macros! So I would much prefer to find a way to make this work with Serverless.

Further reading on Single Environment vs Multi-Environment

Activity

  1. eeroniemi commented on Jun 19, 2019

    @eeroniemi

    I believe this issue is (at least partially) duplicate with #5315 and it's now implemented (via PR #6196) and is available on release 1.45.0 (2019-06-12).

  2. changed the title [-]Artifact Promotion: Deploy Without Uploading to S3[/-] [+]Artifact Promotion across AWS Accounts[/+] on Jul 10, 2019
  3. RaniSputnik commented on Jul 10, 2019

    @RaniSputnik
    Author

    With more time to consider this I've come to learn a bit more about how Serverless works and I don't believe the PR linked above solves my problem.

    The real root-cause of the issue for me is the serverless-state.json file that gets produced as part of packaging. That file contains account specific information which is not at all what I want. Ideally, I want serverless package to produce an artifact that I could deploy to any AWS account.

    In my original writing, I think I conflated artifact promotion with single lambda packages. I had in my mind the idea that we'd have a shared S3 bucket (cross account) that contained all our package artifacts and we would point all of our deployed lambdas at the zip files in that single bucket. That's not really what I need - doesn't matter if the same artifact is uploaded to S3 multiple times, but I need to be able to deploy the result of a serverless package to multiple AWS accounts.

    Hope that makes sense.

  4. bobthemighty commented on Apr 26, 2024

    @bobthemighty

    Darn it @RaniSputnik . I just found this while still trying to solve this same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions