Select Language:
Setting up environment variables in AWS App Runner can be straightforward, even if you don’t see a dedicated section for them in the console. The key is to use the apprunner.yaml configuration file, which you’ve already started working with.
In your apprunner.yaml file, you’ll want to specify environment variables in two sections: ‘env’ for simple text variables and ‘secrets’ for sensitive data stored in AWS Secrets Manager or Systems Manager Parameter Store. Here’s a simple structure you can follow:
version: 1.0
runtime: python3
build:
commands:
build:
– pip install -r requirements.txt
run:
command: python manage.py runserver
network:
port: 8000
env:
– name: DJANGO_SETTINGS_MODULE
value: “your_project.settings”
secrets:
– name: DB_NAME
value-from: “arn:aws:secretsmanager:region:account-id:secret:your-secret-name”
– name: DB_HOST
value-from: “arn:aws:secretsmanager:region:account-id:secret:your-secret-name”
– name: DB_USER
value-from: “arn:aws:secretsmanager:region:account-id:secret:your-secret-name”
One common problem is that the IAM role your App Runner service uses might not have the right permissions to access Secrets Manager. Make sure this role has a policy attached that allows the ‘secretsmanager:GetSecretValue’ action for the secrets you’re accessing.
Remember, environment variables and secrets listed under ‘run’ are only available during runtime. They won’t be accessible during the build process — so avoid trying to use them when installing dependencies, like during ‘pip install’. Instead, keep database credentials and other secrets for when your Django app is actually running.
If the AWS console isn’t showing the options you need, you can also manage environment variables using the AWS CLI or App Runner API.
For more details, you can check out the official AWS documentation on managing environment variables in App Runner.




