To define a single file Lambda function:
/functions
myBlueFunction.mjs
A single file function must export 2 things: a handler, and a config object:
export const config = {
// ...my config. More details below
}
export const handler = async (event, rise, context) => {
return 123
}
To define a folder function:
/functions
/myBlueFunction
/node_modules
utils.mjs
index.mjs
The index.mjs file inside the folder, like the single file function, must export 2 things: a handler, and a config object:
export const config = {
// ...my config. More details below
}
export const handler = async (event, rise, context) => {
return 123
}
The config object is how you configure your Lambda function.
If url
is set to true, your lambda function will deploy with a public url. The format of the string is {METHOD} {PATH
export const config = {
url: 'GET /notes'
}
If eventRule
is defined, rise-functions will setup an event bridge rule to trigger your lambda function
export const config = {
eventRule: {
source: 'user-service',
event: 'user-created',
eventBus: 'my bus' // optional, Defaults to "default"
}
}
If permissions
is set, you can add an array of IAM permissions to your Lambd function:
export const config = {
permissions: [
{
Effect: 'Allow',
Action: 'dynamodb:Query',
Resource: 'arn:aws:dynamodb:us-east-1:123412341234:table/myTable'
}
]
}
If env
is defined, rise-functions provide the values defined in this object as environment variables. Your lambda function code will be able to reference them with process.env.STRIPE_ID
.
export const config = {
env: {
STRIPE_ID: '12341234'
}
}
Timeout is set to 6 seconds by default. If you need your lambda function to run longer, you can increase the timeout to up to 900 seconds (15 minutes)
export const config = {
timeout: 300
}
If alarm
is defined, rise-functions will create a CloudWatch Alarm on your lambda function to track errors.
export const config = {
alarm: {
threshold: 3, // number of errors that will trigger this alarm
snsTopic: 'mytopic that sends notification somewhere',
period: 60, // number of seconds the threshold will be evaulated. Valid values are 10, 30, 60, and any multiple of 60.
evaluationPeriods: 4,
description: 'helpful text'
}
}