aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.66k stars 1.01k forks source link

Layers and environment variables do not work #1484

Closed dumim closed 4 years ago

dumim commented 4 years ago

Hi,

I am using bitbucket pipelines (python image version 3.8.5) to deploy my pure lambda code that is triggered by a cloudwatch trigger. The lambda and the cloudwatch event rule is created and the is updated on AWS. But my layer is not added (under layers it shows (0)), and my enviornment variable is not set ([ERROR] KeyError: 'TEST_VAR' error message when accessing the variable)

My config.json is:

{
  "version": "2.0",
  "app_name": "etl",
  "stages": {
    "dev": {
      "lambda_functions": {
        "etl_lambda": {
          "lambda_timeout": 300,
          "reserved_concurrency": 1,
          "layers": [
            "arn:aws:lambda:ap-southeast-2:xxxxxxxxxx"
          ],
          "environment_variables": {
            "TEST_VAR": "foo"
          }
        }
      }
    }
  }
}

and my app.py :

from chalice import Chalice
import os

app = Chalice(app_name='etl')

@app.schedule('rate(1 minute)')
def lambda_handler(event):
    print (os.environ)
    print(os.environ["TEST_VAR"])

Running chalice --version in the bitbucket pipeline during deployment shows chalice 1.17.0, python 3.8.5, linux 4.19.128-flatcar

Any help, tips or insights will be appreciated. Been stuck on this for 4 days.

jamesls commented 4 years ago

Hi, sorry you're running into this. What commands are you using to deploy your application? Are you using the chalice deploy command or the chalice package command? As far as I can tell your config.json and app.py file look correct so this should work without issues. One thing to keep in mind is if you're using chalice deploy then the state file it uses to track what's deployed is a local file so if this is running in some type of CI system that doesn't persist files it's possible Chalice won't know what resources exist. The next steps would be to look at either the debug logs if you're using chalice deploy or the generated template if you're using chalice package.

no-response[bot] commented 4 years ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

dumim commented 4 years ago

@jamesls thanks for that and sorry for the delay in responding. I was using chalice deploy. I have since moved to Serverless since I wasn't able to figure out the issue. Thanks