Runtime values support for the AWS CDK
Project description
Runtime Values
The CDK allows apps to advertise values from construction time to runtime code. For example, consider code in a Lambda function which needs to know the URL of the SQS queue created as part of your CDK app.
Runtime values are advertised as textual SSM parameters with the following key:
/rtv/<stack-name>/<package>/<name>
Therefore, in order to advertise a value you will need to:
- Make the current stack name available as an environment variable to your
runtime code. The convention is to use
RTV_STACK_NAME
. - Use the
RuntimeValue
construct in order to create the SSM parameter and specify least-privilege permissions.
For example, say we want to publish a queue's URL to a lambda function.
Construction Code
import { RuntimeValue } from '@aws-cdk/runtime-values'
const queue = new Queue(this, 'MyQueue', { /* props.... */ });
const fn = new Lambda(this, 'MyFunction', { /* props... */ });
const fleet = new Fleet(this, 'MyFleet', { /* props... */ });
// this line defines an AWS::SSM::Parameter resource with the
// key "/rtv/<stack-name>/com.myorg/MyQueueURL" and the actual queue URL as value
const queueUrlRtv = new RuntimeValue(this, 'QueueRTV', {
package: 'com.myorg',
name: 'MyQueueURL',
value: queue.queueUrl
});
// this line adds read permissions for this SSM parameter to the policies associated with
// the IAM roles of the Lambda function and the EC2 fleet
queueUrlRtv.grantRead(fn.role);
queueUrlRtv.grantRead(fleet.role);
// adds the `RTV_STACK_NAME` to the environment of the lambda function
// and the fleet (via user-data)
fn.env(RuntimeValue.ENV_NAME, RuntimeValue.ENV_VALUE);
fleet.env(RuntimeValue.ENV_NAME, RuntimeValue.ENV_VALUE);
Runtime Code
Then, your runtime code will need to use the SSM Parameter Store AWS SDK in order to format the SSM parameter key and read the value. In future releases, we will provide runtime libraries to make this easy.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aws-cdk.runtime-values-0.29.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1d8f6c6d0a98caeb88fe5dcf43ee727ac8ee27023a9176dfd63df5ee7243320 |
|
MD5 | 49565a2d38daa479aedc84ee3a7207b9 |
|
BLAKE2b-256 | 59f0099d1caf82b3734f6f300fab3e4324a06d32d217892dc1260955c80c735c |
Hashes for aws_cdk.runtime_values-0.29.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fde260d41b77abf4b7cb852f6b1e48a78822a5c0b0d3ca832ec10445c666aea |
|
MD5 | 86ae4d927db98b4e54665f7b4a8233a7 |
|
BLAKE2b-256 | ce66c2d89754dce9f0586dfab7679fec868866bb1e11fe271addc8df8a597ee6 |