sst.dev icon indicating copy to clipboard operation
sst.dev copied to clipboard

Comments: Deploy Again

Open jayair opened this issue 9 years ago • 24 comments

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

jayair avatar Apr 10 '17 01:04 jayair

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 avatar Apr 21 '17 17:04 geirman

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

jayair avatar Apr 21 '17 18:04 jayair

@geirman added your suggestion to the chapter febd147b52b8a94bb8a23b2ded62dda4b6813a07

jayair avatar Apr 30 '17 02:04 jayair

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 avatar May 05 '17 18:05 PatrykTies

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

jayair avatar May 05 '17 20:05 jayair

Win7 Pro 64bit SP1

PatrykTies avatar May 05 '17 22:05 PatrykTies

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

jayair avatar May 05 '17 22:05 jayair

Let me google it out and investigate. Cheers

PatrykTies avatar May 05 '17 22:05 PatrykTies

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

PatrykTies avatar May 05 '17 22:05 PatrykTies

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 avatar May 05 '17 23:05 PatrykTies

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

jayair avatar May 06 '17 18:05 jayair

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 avatar May 16 '17 01:05 ryanjcruz

@ryanjcruz Are you on Windows?

jayair avatar May 16 '17 17:05 jayair

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

ryanjcruz avatar May 17 '17 09:05 ryanjcruz

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

jayair avatar May 17 '17 16:05 jayair

@jayair see my package.json

https://github.com/ryanjcruz/notes-app-client/blob/master/package.json

ryanjcruz avatar May 18 '17 08:05 ryanjcruz

@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 avatar May 18 '17 17:05 jayair

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

ryanjcruz avatar May 19 '17 07:05 ryanjcruz

@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

ryanjcruz avatar May 27 '17 01:05 ryanjcruz

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?

littleredshack avatar Dec 13 '17 06:12 littleredshack