Deploy Again

#1

From @jayair on Mon Apr 10 2017 01:10:38 GMT+0000 (UTC)

Link to chapter - http://serverless-stack.com/chapters/deploy-again.html

Copied from original issue: https://github.com/AnomalyInnovations/serverless-stack-com/issues/70

#2

From @geirman on Fri Apr 21 2017 17:22:59 GMT+0000 (UTC)

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
#3

From @jayair on Fri Apr 21 2017 18:39:57 GMT+0000 (UTC)

@geirman right on! I’ll remember to add this detail when I update things.

#4

From @jayair on Sun Apr 30 2017 02:02:46 GMT+0000 (UTC)

@geirman added your suggestion to the chapter febd147b52b8a94bb8a23b2ded62dda4b6813a07

#5

From @PatrykTies on Fri May 05 2017 18:07:18 GMT+0000 (UTC)

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"
}
#6

From @jayair on Fri May 05 2017 20:08:12 GMT+0000 (UTC)

@PatrykTies that is weird. Which OS are you on btw?

#7

From @PatrykTies on Fri May 05 2017 22:43:11 GMT+0000 (UTC)

Win7 Pro 64bit SP1

#8

From @jayair on Fri May 05 2017 22:45:07 GMT+0000 (UTC)

@PatrykTies Ah I’m not too familiar with the shell in Windows but maybe the escape \ works differently there?

#9

From @PatrykTies on Fri May 05 2017 22:46:28 GMT+0000 (UTC)

Let me google it out and investigate. Cheers

#10

From @PatrykTies on Fri May 05 2017 22:47:15 GMT+0000 (UTC)

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

#11

From @PatrykTies on Fri May 05 2017 23:05:34 GMT+0000 (UTC)

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

#12

From @jayair on Sat May 06 2017 18:42:57 GMT+0000 (UTC)

@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.

#13

From @ryanjcruz on Tue May 16 2017 01:53:29 GMT+0000 (UTC)

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 '/*'

#14

From @jayair on Tue May 16 2017 17:14:11 GMT+0000 (UTC)

@ryanjcruz Are you on Windows?

#15

From @ryanjcruz on Wed May 17 2017 09:32:28 GMT+0000 (UTC)

@jayair yep windows 10, but using git bash to run the command

#16

From @jayair on Wed May 17 2017 16:55:25 GMT+0000 (UTC)

@ryanjcruz I see. How do you combine two shell commands together?

#17

From @ryanjcruz on Thu May 18 2017 08:31:15 GMT+0000 (UTC)

@jayair see my package.json

#18

From @jayair on Thu May 18 2017 17:41:40 GMT+0000 (UTC)

@ryanjcruz Hmm. Isn’t that the same as the source repo? - https://github.com/AnomalyInnovations/serverless-stack-demo-client/blob/master/package.json#L22

#19

From @ryanjcruz on Fri May 19 2017 07:51:02 GMT+0000 (UTC)

@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

notes-app-client@0.1.0 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.

#20

From @ryanjcruz on Sat May 27 2017 01:01:44 GMT+0000 (UTC)

@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