Managing Environment Variables with AWS Secrets Manager for App Runner
This guide explains how to securely manage production environment variables for an AWS App Runner backend project using AWS Secrets Manager.
Creating Secrets
- Navigate to the AWS Secrets Manager dashboard
- Click "Store a new secret"
- Select "Other type of secret" as the secret type
- Enter your key/value pairs
- Choose an encryption key (use AWS default or create a new one)
- Complete the "Configure secret" and "Configure rotation" steps
- After creation, copy the "Secret ARN" from the details page
Granting Permissions
To allow your App Runner service to retrieve the secrets:
- Open the AWS IAM service and go to "Roles"
- Select your App Runner's assigned role or create a new one
- Click "Add permission" and choose "Create inline policy"
- Switch to JSON mode and paste the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetSecretValue",
"kms:Decrypt*"
],
"Resource": [
"arn:aws:secretsmanager:<region>:<aws_account_id>:secret:<secret-name>",
"arn:aws:kms:<region>:<aws_account_id>:key/<key-id>"
]
}
]
}
This policy grants two permissions:
- Access to your Secrets Manager secret
- Access to the encryption key
- Save the policy
- Return to App Runner and rebuild your instance
By following these steps, you'll securely manage your environment variables using AWS Secrets Manager for your App Runner deployment.