Repository navigation
Description
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
eeroniemi commentedon Jun 19, 2019
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).
[-]Artifact Promotion: Deploy Without Uploading to S3[/-][+]Artifact Promotion across AWS Accounts[/+]RaniSputnik commentedon Jul 10, 2019
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.jsonfile that gets produced as part of packaging. That file contains account specific information which is not at all what I want. Ideally, I wantserverless packageto 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 packageto multiple AWS accounts.Hope that makes sense.
apatap commentedon May 6, 2020
Maybe this plugin could help: https://github.com/cipri-p/serverless-package-location-customizer
bobthemighty commentedon Apr 26, 2024
Darn it @RaniSputnik . I just found this while still trying to solve this same problem.