silvermine / serverless-plugin-cloudfront-lambda-edge

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

Missing environment. #56

Closed msalidu closed 4 years ago

msalidu commented 4 years ago

The enviroments variables disappear in the generated template:

urlRedirectFunction:
  description: "Lambda@edge url rewrite - ${self:custom.stage} [${opt:omversion}]"
  handler: omredir/redir_handler.lambda_handler
  memorySize: 128
  timeout: 10
  environment:
     DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
     LOG_LEVEL: 'INFO'
  lambdaAtEdge:
      distribution: 'UrlRewriteDistribution'
      eventType: 'origin-request'

Template:

"UrlRedirectFunctionLambdaFunction": {
  "Type": "AWS::Lambda::Function",
  "Properties": {
    "Code": {
      "S3Bucket": {
        "Ref": "ServerlessDeploymentBucket"
      },
      "S3Key": "xxxxx/om-urlredirector.zip"
    },
    "FunctionName": "om-urlredirector-test-urlRedirectFunction",
    "Handler": "omredir/redir_handler.lambda_handler",
    "MemorySize": 128,
    "Role": {
      "Fn::GetAtt": [
        "IamRoleLambdaExecution",
        "Arn"
      ]
    },
    "Runtime": "python3.7",
    "Timeout": 10,
    "Description": "Lambda@edge url rewrite - test [1.1.2]",
    "TracingConfig": {
      "Mode": "PassThrough"
    }
  },
  "DependsOn": [
    "UrlRedirectFunctionLogGroup"
  ]
}

Thanks a lot, Massimo

msalidu commented 4 years ago

Environment variables are not supported by Lambda@Edge as specified in the limitations documentation. :(

jthomerson commented 4 years ago

@msalidu correct. We have to remove the env vars because Lambda@Edge doesn't support them. If you need dynamic variables put into your L@E environment, you might try something like this: https://www.npmjs.com/package/dotenv

jthomerson commented 4 years ago

@msalidu also, this may be helpful to you: https://www.serverless.com/plugins/serverless-dotenv-plugin/