-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
s3 auto deploy should be done before cloudformation deployment #46
Comments
I don't feel like it would solve the case I had in #19 because I wasn't using cloudformation at all. I was only trying to upload files to a part of stack that lives continously. The history of my project after #19 was filed was that I left this plugin and sls at all and I wrote a shell script that uses aws cli (sync) for all assets and then when it's done it does the same for the |
The Serverless Framework does use CloudFormation under the hood to create all the AWS Lambda and Api Gateway but is trasparent to the final user. |
I'd also be interested in this. But there seems to be an easy workaround. But there needs to be a better option to remove old assets after the deploy.
But I noticed that |
My original thinking (as far as I recall it) is the CF config would be creating the bucket, potentially, so you couldn't upload to it before the deploy. I'd certainly welcome an option to let you control if it happened before or after, to remove this assumption. |
In the meanwhile I forked this repo and made one with a fix for this specific problem which I use in production:
This way all assets are uploaded to the S3 bucket before Serverless event starts deploying the serverless zip file. |
@giorgio-zamparelli have you considered contributing to this repo? |
@funkybob would you merge a PR with a solution where the paramater auto can be a boolean OR a string specifying the hook? It would be retrocompatible this way:
|
For documentation purposes, my deployment now looks like this: sls s3deploy --stage=prod || ASSET_DEPLOYMENT_FAILED=$true
sls deploy --stage=prod --conceal
if [ $ASSET_DEPLOYMENT_FAILED ]; then sls s3deploy --stage=prod; fi This now works on first deploy and on any consecutive deploy as well as on changes. |
@giorgio-zamparelli moving this to the When executing
There's no way to bypass this except by removing the plugin from the serverless.yml file. Adding a check here to see if the cloudformation stack exists or adding an error message would be a nice addition (for anyone else who may experience this): |
I stopped using Serverless Framework in favor of AWS CDK. |
@Nemo64 This is nice but s3deploy doesn't seem to have any exit codes different than 0 so your logic might not work. Did you manage to test it? |
Mhh, now that you mention it, it could be that I never had an initial deploy with it. But my preferred deployment strategy actually changed again because s3deploy became just way too slow with a growing number of files and the fact that I also couldn't delete outdated files without deleting all of them first. It now involves this shell script, which reads the #!/usr/bin/env bash
set -e
STAGE="${1}"
BUCKET="$(sls info --stage=$STAGE -v|grep AssetsBucket:|cut -d ' ' -f2)"
OPTIONS="${@:2}"
echo stage: $STAGE
echo bucket: $BUCKET
echo options: $OPTIONS
if [ -z $BUCKET ]
then
echo "no bucket bath found"
exit 1
fi
aws s3 sync public/build "s3://${BUCKET}/build" --exclude="*" --include="????????????????????*.*" --cache-control="public, max-age=31536000, immutable" $OPTIONS
# more lines here And my deployment now does this
|
Thanks a lot for sharing that. |
The auto deploy of this plugin uploads the assets to the S3 bucket AFTER the cloudformation stack has been deployed.
In my use case (and possibly everyone's use case) the upload of the assets should happen BEFORE the cloudformation stack has been deployed.
SOLUTION
Change the hook event used from
after:deploy:finalize
to another hook event happening before the deployment like for examplebefore:deploy:deploy
MY USE CASE (probably everyone's)
I'm using serverless-s3-deploy to upload some bundles for a SPA.
In my case I'm uploading 30+ bundles and it takes sometimes.
The auto deploy of this plugin happens after the deployment stage of the cloudformation stack. At that point Api Gateway and AWS Lambda are already answering with an index.html file that is pointing to a bundle that is still being uploaded by the serverless-s3-deploy.
LIKELY FIX #19 AS WELL
This would likely fix also this issue #19 since the order of the bundles wouldn't matter anymore since they are deployed all before the cloudformation stack. What do you think @jrencz?
The text was updated successfully, but these errors were encountered: