Comments: Deploy Again
Link to chapter - http://serverless-stack.com/chapters/deploy-again.html
So for this section, I did something simple and pretty cool that I think would easily add value to this chapter. I added deploy scripts to the package.json. Here's what they look like...
"predeploy": "npm run build",
"deploy": "aws s3 sync build/ s3://YOUR_S3_DEPLOY_BUCKET_NAME",
"postdeploy": "aws cloudfront create-invalidation --distribution-id YOUR_CF_DISTRIBUTION_ID --paths '/*' && aws cloudfront create-invalidation --distribution-id YOUR_WWW_CF_DISTRIBUTION_ID --paths '/*'"
Now, I can update my files and simply...
$ npm run deploy
@geirman right on! I'll remember to add this detail when I update things.
@geirman added your suggestion to the chapter febd147b52b8a94bb8a23b2ded62dda4b6813a07
It gives me error for CloudFront, Invalid invalidation paths I found a tip here : https://kylewbanks.com/blog/invalidate-entire-cloudfront-distribution-from-command-line THIS THROW ERROR: aws cloudfront create-invalidation --distribution-id YOUR_CF_DISTRIBUTION_ID --paths '/*'
THIS IS WORKING: showing invalidations in AWS console but page dont update aws cloudfront create-invalidation --distribution-id YOUR_CF_DISTRIBUTION_ID --paths '/*' (adding \ here before astrix ) I tried all combinations and only above give some response from AWS Weird...any1 have a clue ?
{
"Invalidation": {
"Status": "InProgress",
"InvalidationBatch": {
"Paths": {
"Items": [
"//*" <========THIS LOOKS WEIRD TO ME
],
"Quantity": 1
},
"CallerReference": "cli-1494008481-711394"
},
"Id": "I1HDDV6762VISK",
"CreateTime": "2017-05-05T18:21:29.619Z"
},
"Location": "https://cloudfront.amazonaws.com/2017-03-25/distribution/E1NKEP
QSUUZHQW/invalidation/I1HDDV6762VISK"
}
@PatrykTies that is weird. Which OS are you on btw?
Win7 Pro 64bit SP1
@PatrykTies Ah I'm not too familiar with the shell in Windows but maybe the escape \ works differently there?
Let me google it out and investigate. Cheers
Btw using npm script also gives the same error....but that get injected into win shell anyways...so
Also i am using gitbash for terminal commands
Solved, for win7 I had to use /^* as --paths, instead of "/*" Thanks for pointing the possible cause. All done Now off me go to Jenkins and AWS codepipeline CI/CD for this tut
@PatrykTies thanks for reporting back. I'm sure it'll help other folks.
Btw, let us know how your Jenkins setup works out, we are considering writing about that as well.
I'm getting an error on postdeploy:
An error occurred (InvalidArgument) when calling the CreateInvalidation operation: Your request contains one or more invalid invalidation paths.
aws cloudfront create-invalidation --distribution-id CF_DISTRIBUTION_ID --paths '/*' && aws cloudfront create-invalidation --distribution-id WWW_CF_DISTRIBUTION_ID --paths '/*'
But when executed individually, they both seem to work
aws cloudfront create-invalidation --distribution-id CF_DISTRIBUTION_ID --paths '/*'
aws cloudfront create-invalidation --distribution-id WWW_CF_DISTRIBUTION_ID --paths '/*'
@ryanjcruz Are you on Windows?
@jayair yep windows 10, but using git bash to run the command
@ryanjcruz I see. How do you combine two shell commands together?
@jayair see my package.json
https://github.com/ryanjcruz/notes-app-client/blob/master/package.json
@ryanjcruz Hmm. Isn't that the same as the source repo? - https://github.com/AnomalyInnovations/serverless-stack-demo-client/blob/master/package.json#L22
@jayair looks like it is, Maybe the syntax has some issues with non-unix like machine. I think the issue for windows is the && part as running them individually seems to go just ok.
Update - nah changing it to & still didn't work though.
Update 2 - hmmm running the command as is not part of npm run deploy seems to be working. Though the error seems to be on that part of the script running the postdeploy task
[email protected] postdeploy C:\Users\Ryan\Documents\Projects\notes-app-client aws cloudfront create-invalidation --distribution-id E1EH1YYONEF1TY --paths '/' & aws cloudfront create-invalidation --distribution-id E3NKA80S86XILI --paths '/'
An error occurred (InvalidArgument) when calling the CreateInvalidation operation: Your request contains one or more invalid invalidation paths.
An error occurred (InvalidArgument) when calling the CreateInvalidation operation: Your request contains one or more invalid invalidation paths.
@jayair finally figured it out on another project, for windows --paths '/*' should be just --paths /* for combined create-invalidation commands on 2 cloudfront distribution ids
Strange one. I have got all the way through the process and all working fine. But when I try to redeploy to S3 I get an error about my AWS key being invalid.
C:\Users\gstokes\Documents\Personal\Coding\Serverless\notes-app-frontend\notes-app-client>aws s3 sync build/ s3://gbs-notes-app-client
fatal error: An error occurred (InvalidAccessKeyId) when calling the ListObjects operation: The AWS Access Key Id you provided does not exist in our records.
I have re-run AWS configure just in case those got changed somehow. Still not working.
Anyone got any ideas?