I have 2 AWS lambda functions belonging to the same account producer and consumer function. I want the producer to schedule the consumer to run at a specified time. When I check under CloudWatch Events the events are being created but the consumer is not being triggered. I am using this link
Producer Code
var AWS = require('aws-sdk');
var cwevents = new AWS.CloudWatchEvents({apiVersion: '2015-10-07'});
var params_for_rule = {
Name: 'DEMO_EVENT',
ScheduleExpression: 'cron(0/3 * * * ? *)',
State: 'ENABLED'
};
var params_for_target = {
Rule: 'DEMO_EVENT',
Targets: [
{
Arn: 'consumer',
Id: 'default',
}
]
};
exports.handler = async (event, context, callback) => {
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
cwevents.putRule(params_for_rule, function(err, data){
if(err){
console.log("Not Working");
}
else{
console.log("Working");
cwevents.putTargets(params_for_target, function(err, data){
if(err){
console.log("Not Working");
}
else{
console.log("Working");
}
});
}
});
};