Search code examples
amazon-web-servicessam

AWS SAM local with AppConfig local development mode


I'm trying to test a Python lambda locally along with the AppConfigAgent lambda extension using the local development mode (https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-retrieving-simplified-methods-local-development.html).

Without local development mode I have this working. I can curl my lambda and it looks up the AppConfig from the real AWS environment and provides the results back.

However when running locally for testing I don't want the real AppConfig to be used but instead values from a configuration file (as per the link above).

I've added the environment variable to my template.yaml file but it doesn't seem to be picked up.

Environment:
  Variables:
    LOCAL_DEVELOPMENT_DIRECTORY: "./appconfig"

Has anyone got this working?

Thanks.

EDIT: Adding sample output when connecting to the running container:

bash-4.2# export | grep AWS_APPCONFIG
declare -x AWS_APPCONFIG_EXTENSION_LOCAL_DEVELOPMENT_DIRECTORY="/var/task/appconfig"
declare -x AWS_APPCONFIG_EXTENSION_LOG_LEVEL="debug"
bash-4.2# ls /var/task/appconfig/ -l
total 8
-rw-r--r-- 1 root root 65 Jan  4 12:15 app:environment:profile
-rw-r--r-- 1 root root 65 Jan  4 12:15 app:environment:profile.json
bash-4.2# curl http://localhost:2772/applications/app/environments/environment/configurations/profile
{"Message":"Application not found","ReferencedBy":{"ApplicationIdentifier":"app"},"ResourceType":"Application"}
bash-4.2#

Solution

  • Use the AWS_APPCONFIG_EXTENSION_LOCAL_DEVELOPMENT_DIRECTORY environment variable.

    When running the agent in Lambda, environment variables are prefixed with AWS_APPCONFIG_EXTENSION_ (see https://docs.aws.amazon.com/appconfig/latest/userguide/appconfig-integration-lambda-extensions.html#appconfig-integration-lambda-extensions-config).

    By the way, I work on the AWS AppConfig team. We’ll update our documentation to make this more clear.