Skip to content

Commit a914fc0

Browse files
authored
feat(apprunner): apprunner secrets manager (#23692)
---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [x] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 3dc40b4 commit a914fc0

14 files changed

+1599
-116
lines changed

packages/@aws-cdk/aws-apprunner/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,39 @@ new apprunner.Service(this, 'Service', {
160160
vpcConnector,
161161
});
162162
```
163+
164+
## Secrets Manager
165+
166+
To include environment variables integrated with AWS Secrets Manager, use the `environmentSecrets` attribute.
167+
You can use the `addSecret` method from the App Runner `Service` class to include secrets from outside the
168+
service definition.
169+
170+
```ts
171+
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
172+
import * as ssm from '@aws-cdk/aws-ssm';
173+
174+
declare const stack: Stack;
175+
176+
const secret = new secretsmanager.Secret(stack, 'Secret');
177+
const parameter = ssm.StringParameter.fromSecureStringParameterAttributes(stack, 'Parameter', {
178+
parameterName: '/name',
179+
version: 1,
180+
});
181+
182+
const service = new apprunner.Service(stack, 'Service', {
183+
source: apprunner.Source.fromEcrPublic({
184+
imageConfiguration: {
185+
port: 8000,
186+
environmentSecrets: {
187+
SECRET: apprunner.Secret.fromSecretsManager(secret),
188+
PARAMETER: apprunner.Secret.fromSsmParameter(parameter),
189+
SECRET_ID: apprunner.Secret.fromSecretsManagerVersion(secret, { versionId: 'version-id' }),
190+
SECRET_STAGE: apprunner.Secret.fromSecretsManagerVersion(secret, { versionStage: 'version-stage' }),
191+
},
192+
},
193+
imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
194+
})
195+
});
196+
197+
service.addSecret('LATER_SECRET', apprunner.Secret.fromSecretsManager(secret, 'field'));
198+
```

0 commit comments

Comments
 (0)