'Send DynamoDB arn from JS file to serverless
With a JS script, I retrieve the stream arn from my DynamoDB table.
I will like to send this arn to serverless.yml file to use it in my function.
My serverless version:
$ serverless -v
Framework Core: 2.71.0 (standalone)
Plugin: 5.5.3
SDK: 4.3.0
Components: 3.18.1
My JS script works:
"use strict";
const AWS = require("aws-sdk");
async function run() {
const region = 'eu-west-3';
const tableName = 'dev-Connect-TrzConnect';
const dynamoDBStreams = await getDynamoDBStreams(region, tableName);
let streamArn = null;
dynamoDBStreams.Streams.forEach((stream) => {
streamArn = stream.StreamArn;
})
return streamArn;
}
const getDynamoDBStreams = async (region, tableName) => {
const dynamoStreams = new AWS.DynamoDBStreams({
region: region,
});
const params = {
TableName: tableName,
};
return dynamoStreams.listStreams(params).promise();
};
run().then((r) => console.log(r))
Now, I have no idea how to retrieve the value of streamArn variable in serverless.yml and, use it there:
functions:
createStatementFiles:
handler: lambda/statement.php
timeout: 899 # 14min 59s
layers:
- arn:aws:lambda:#{AWS::Region}:<account_id>:layer:php-73:1
role: CreateStatementFilesRole
reservedConcurrency: 10
events:
- stream:
type: dynamodb
arn: ${streamArn}
filterPatterns:
- eventName: [INSERT]
dynamodb:
NewImage:
__partitionKey:
S: [statementBalance]
I search to have something like this:
- stream:
type: dynamodb
arn: ${streamArn}
I read this documentation https://www.serverless.com/framework/docs/guides/plugins/creating-plugins but I did not understand at all how to solve my need.
Can you please help me ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
