aws-samples/cloudfront-authorization-at-edge

Unable to change the code and update deployment

RuyOliveiraRunaHR opened this issue · 8 comments

Hi Guys !
I'm sorry for being bothering you here, but I really need some help !!
I've cloned the repo, followed all the guide lines on "Option 3: Deploy with SAM CLI" and it worked perfectly, my congratulations to the Chief !!
Now I've changed some details in the code, basically the error messages to fit into my needs, and I'm try to deploy the new code, but It doens't work.
I'm re-running "npm run build", "sam build" and then "sam package", when I run this last I saw the a lot of message like "File with same data already exists at 362de04878a4594fdfe7216ff7733b50, skipping upload".

Next, when I run "sam deploy" it says "Error: No changes to deploy. Stack static-site-test-v4 is up to date".

At the end, I'm not able to update the code in cloudformation/lambda amd I'm stuck in this for one day, please give any advice on this.

Thanks in advance.
Sorry for being too rookie !!

Increment parameter Version upon redeploying, that makes sure all Lambda@Edge functions get redeployed

Thanks Otto for your help.
Just to clarify, I'm making a change in code of src->lambda-edge->check-auth->index.ts file.
I'm going to take a look at the link above.
Thanks once again.

Opss...I did something wrong:
I've edited the file template.yaml at the root directory as below:

  CheckAuthHandler:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: src/lambda-edge/check-auth/
      Handler: bundle.handler
      Role: !GetAtt LambdaEdgeExecutionRole.Arn
      Timeout: 5
      Version: 2  # Dummy field, change this to force CloudFormation to deploy this resource if none of the other properties change

and now I'm getting to following error when I run sam build:

samcli.commands.validate.lib.exceptions.InvalidSamDocumentException: [InvalidResourceException('CheckAuthHandler', 'property Version not defined for resource of type AWS::Serverless::Function')] ('CheckAuthHandler', 'property Version not defined for resource of type AWS::Serverless::Function')

any advice ? Thanks.

Don't put them on the AWS::Serverless::Function but instead on the custom resources for the code update (they publish the Lambdas to a new version, and inject config into them).

Easiest way: you can just use the parameter overrides when deploying, as Version is a parameter of this template, and passed to the custom resources.

So sam deploy --template-file packaged.yaml --stack-name <Your Stack Name> --capabilities CAPABILITY_IAM --parameter-overrides "Version=<specify a new version here every time you want the Lambda Custom Resources to redeploy>"

Hi Otto,
Thanks for your help, it worked perfectly !
One thing more, have you used samconfig.toml to create multiple environments? did it worked ?
In my case, I'm trying to create develop and prodction envs, but it looks like sam deploy is not reading parameter-overrrides from samconfig.toml.

Thanks once again.

it worked perfectly

Awesome! 🎉

One thing more, have you used samconfig.toml to create multiple environments? did it worked ?

Sorry mate I'm not an expert on that. I usually use plain sam deploy statements, just make sure to switch to the s3 deployment bucket in the right account.

Hi Otto !
No problem, thanks for all your assistance !