Keywords are a way to reference dynamic values in your rise.mjs file or functionconfig, you can reference:
All keywords use the following format: {@keyword}
.
It is common to deploy to many stages, and there may be times you want to reference a value or resource based on the stage you are in. You can do this by using the stage keyword:
const stage = '{@stage}'
An example of when you might use stage is to pass this as an env variable into your Lambda function:
// config.mjs
export const config = {
env: {
STAGE: '{@stage}',
SOME_ENDPOINT: 'https://myendpoint-{@stage}.com'
}
}
You can reference the region as follows:
const region = '{@region}'
An example of when you might use region is to build up an arn value:
// config.mjs
export const config = {
env: {
TOPIC: 'arn:aws:sns:{@region}:12341234:ChatOpsTopic'
}
}
You can reference your account id as follows:
const accountId = '{@accountId}'
An example of when you might use accountId is to build up an arn value:
// config.mjs
export const config = {
permissions: [
{
Effect: 'Allow',
Action: 'dynamodb:Query',
Resource: 'arn:aws:dynamodb:us-east-1:{@accountId}:table/myTable'
}
]
}
Every deployed CloudFormation template has the option of defining outputs. This is great for dynamically referring to resource names or resource arns. Example, if you have deployed the following template:
Resources:
Notes:
Type: 'AWS::DynamoDB::Table'
Properties:
#...bunch of properties
Outputs:
NotesArn:
Value:
'Fn::GetAtt':
- Notes
- Arn
The ARN of the table is made available for us to reference by refering to the NotesArn output. You can reference this value with the following keyword:
const arn = '{@output.stackName.NotesArn}'
A common scenario for using outputs would be to define iam permissions for a lambda function, Example:
// config.mjs
export const config = {
permissions: [
{
Effect: 'Allow',
Action: 'dynamodb:Query',
Resource: '{@output.stackName.NotesArn}'
}
]
}
SSM Parameter Store is an AWS service for storing parameters in your account. This can be likened to other services like Github or Vercel which allow you to set env variables to reference in your deployment pipeline. It is important to note that you should not use parameter store if the value is a secret. Consider using AWS Secret Manager for senstive secrets and keys, and parameter store for values you are fine being visible as plain text in code or in Lambda config.
You can reference a parameter as follows:
const endpoint = '{@ssm.external_service_endpoint}'
An example of when you might use ssm is to pass this as an env variable into our Lambda function:
// config.mjs
export const config = {
env: {
EXTERNAL_SERVICE_ENDPOINT: '{@ssm.my_external_service_endpoint}'
}
}