I am facing an issue while configuring AWS Lambda with EventBridge. I set up the scheduling, but when I create the schedule, it gets executed immediately upon creation and does not follow the intended schedule.
Here is the code I am using:
import { CreateItemBody } from '../interfaces/bodyRequest';
import { eventBridgeParamsRequest } from '../interfaces/createEvent';
const eventBridgeClient = new EventBridgeClient({region: "us-east-2"});
export const configureItemSchedule = async (event: CreateItemBody): Promise<PutEventsCommandOutput> => {
const date = new Date();
const addThirtySeconds = date.setTime(date.getTime() + 30000)
const eventParams: eventBridgeParamsRequest = {
time: new Date(addThirtySeconds),
source: "my.apisource",
detailType: "create_event",
eventBusName: "default",
Detail: JSON.stringify(event)
}
console.log(eventParams);
const createEvent = await createItemSchedule(eventParams);
return createEvent;
};
const createItemSchedule = async (parameter: eventBridgeParamsRequest): Promise<PutEventsCommandOutput> => {
const eventParams: PutEventsCommandInput = {
Entries: [
{
Time: parameter.time,
Source: parameter.source,
EventBusName: parameter.eventBusName,
DetailType: parameter.detailType,
Detail: parameter.Detail
},
],
};
try {
const command = new PutEventsCommand(eventParams)
const response = await eventBridgeClient.send(command);
return response;
} catch (e) {
throw new Error(e as string);
}
};
What could be wrong? How can I ensure that the event is scheduled for the correct time and not executed immediately?
Any help is appreciated!
I created EventBridge manually and I am experiencing this issue
Misael Miranda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.