silvermine / serverless-plugin-cloudfront-lambda-edge

Adds Lambda@Edge support to Serverless
MIT License
296 stars 41 forks source link

problems redeploying functions #8

Closed ghost closed 6 years ago

ghost commented 6 years ago

I'm able to deploy a function. And when I hit a cloudfront endpoint, I see messages logged into CloudWatch. Progress!

However when I try to redeploy with: $ serverless deploy --function f

The new function shows up in lambda dashboard, but never propagates. I've tried waiting overnight (12 hours) no luck. Still seeing the OLD CODE console.log('123'); message out in cloudwatch.

When I redeploy the complete package:

$ serverless deploy

I get an error about environment variables. (I did not create any myself)

`levanter:viewerEdgeNode sean$ serverless deploy --verbose Serverless: Packaging service... Serverless: Excluding development dependencies... Serverless: Updated Lambda assume role policy to allow Lambda@Edge to assume the role Serverless: Removing 2 environment variables from function "DirectoryRootViewerRequestRewriterLambdaFunction" because Lambda@Edge does not support environment variables Serverless: Service files not changed. Skipping deployment... Service Information service: viewer-edge-site stage: sean region: us-east-1 stack: viewer-edge-site-sean api keys: None endpoints: None functions: directoryRootViewerRequestRewriter: viewer-edge-site-sean-directoryRootViewerRequestRewriter

Stack Outputs DirectoryRootViewerRequestRewriterLambdaFunctionQualifiedArn: arn:aws:lambda:us-east-1:740445512671:function:viewer-edge-site-sean-viewer-request:3 ServerlessDeploymentBucketName: viewer-edge-site-sean-serverlessdeploymentbucket-ljimy07m7sak

Serverless: Checking to see if 1 function needs to be associated to CloudFront Serverless: Distribution "ViewerDistribution" is now in "Deployed" state Serverless: Updating viewer-request to use arn:aws:lambda:us-east-1:740445512671:function:viewer-edge-site-sean-viewer-request:3 (was arn:aws:lambda:us-east-1:740445512671:function:viewer-edge-site-sean-viewer-request:2) Serverless: Updating distribution "ViewerDistribution" because we updated Lambda@Edge associations on it

Serverless Error ---------------------------------------

The function cannot have environment variables. Function: arn:aws:lambda:us-east-1:740445512671:function:viewer-edge-site-sean-viewer-request:3

Get Support -------------------------------------------- Docs: docs.serverless.com Bugs: github.com/serverless/serverless/issues Forums: forum.serverless.com Chat: gitter.im/serverless/serverless

Your Environment Information ----------------------------- OS: darwin Node Version: 9.4.0 Serverless Version: 1.25.0

levanter:viewerEdgeNode sean$ `

Any thoughts on REDEPLOYing code?

ghost commented 6 years ago

There was a serverless error around environment variables. These appear not to be supported with lambda@edge. Just comment out these lines in serverless.yml:

environment:

SLS_SVC_NAME: ${self:service}

SLS_STAGE: ${self:custom.stage}

ghost commented 6 years ago

From the lamdba@edge docs, it appears each time you upload a lambda function it becomes a new version. Great. However, it appears also that these new versions must be published @edge. It's not clear how this is done. From the lambda dashboard I've tried selecting Actions->publish new version and also Qualifiers->Versions, but with no luck.

Also when I select the cloudfront trigger, it says configuration required. So I scroll down and click "enable trigger & replicate" but the ADD button remains inactive & grayed out.

Thoughts?

jthomerson commented 6 years ago

@hullsean sorry for the delay. When you deploy with sls deploy function -f foo, Serverless is literally just deploying the function code. A new version will be created, but this plugin does not run, and thus the new version is not associated with your CloudFront distribution. You need to do a full deploy to get the new version associated with CloudFront.

I have no idea why you would get your second error (from sls deploy) about the function containing environment variables because the logs also say that the plugin correctly removed environment variables. See:

Serverless: Removing 2 environment variables from function "DirectoryRootViewerRequestRewriterLambdaFunction" because Lambda@Edge does not support environment variables Serverless Error --------------------------------------- The function cannot have environment variables.

Have you tried doing an sls deploy --force to see if that fixed the problem?

I'm going to close the issue because I can't reproduce it. However, if you have more information, or can still reproduce it (and can give us a reproducible test case), feel free to re-open the issue.

ghost commented 6 years ago

Thx Jeremy!