I have observed some unusual behavior with my AWS Lambda function.
Here is the code snippet for the Lambda:
import { TwitterApi } from 'twitter-api-v2';
const client = new TwitterApi({
appKey: 'APP_KEY',
appSecret: 'APP_SECRET',
accessToken: 'ACCESS_TOKEN',
accessSecret: 'ACCESS_SECRET',
});
const rwClient = client.readWrite
exports.handler = async function (event: any) {
event.Records.forEach((record: any) => {
console.log('Event Name: %s', record.eventName);
console.log('DynamoDB Record: %j', record.dynamodb);
switch (record.eventName) {
case "INSERT":
rwClient.v1.tweet('Hello, this is a test.');
break;
default:
break;
}
});
};
When I insert an element into DynamoDb, the EventHandler triggers and should call
rwClient.v1.tweet('Hello, this is a test.');
Theoretically, this should work. However, even though both console.logs before and after the statement are executed, no tweet is sent to the connected twitter account.
If I execute the following code snippet on , the tweet appears in the account:
const twitter_api_v2_1 = require("twitter-api-v2");
const client = new twitter_api_v2_1.TwitterApi({
appKey: 'APP_KEY',
appSecret: 'APP_SECRET',
accessToken: 'ACCESS_TOKEN',
accessSecret: 'ACCESS_SECRET',
});
const rwc = client.readWrite;
rwc.v1.tweet('Hello, this is a test.');
Does anyone have a solution to make the Lambda function work as expected?