我有一个配置了 EventBridge(CloudWatch Events) 触发器的 aws lambda。这个 lambda 工作正常。现在我需要用 Cucumber 测试用例来测试这个 lambda。Lambda 由 AWS skd 版本 2 制成。
我从链接尝试了下面的代码,我可以看到 System.out -> Event Id: ........,但是它没有调用 lambda 函数
EventBridgeClient eventBridgeClient = EventBridgeClient.builder().build();
PutEventsRequestEntry requestEntry = PutEventsRequestEntry.builder()
.time(Instant.now()) // eg: to get current time
.resources("my lambda arn") // eg: arn:aws:lambda:eu-east-1:123456789:function:myLambdaFunction
.source("my lambda package name") //eg: com.package.lambda
.detailType("Scheduled Event")
.detail("{}")
.build();
List <PutEventsRequestEntry> requestEntries = new ArrayList <PutEventsRequestEntry>();
requestEntries.add(requestEntry);
PutEventsRequest eventsRequest = PutEventsRequest.builder().entries(requestEntries).build();
PutEventsResponse result = eventBridgeClient.putEvents(eventsRequest);
for (PutEventsResultEntry resultEntry: result.entries()) {
if (resultEntry.eventId() != null) {
System.out.println("Event Id: " + resultEntry.eventId()); // This is getting with some eventid
} else {
System.out.println("PutEvents failed with Error Code: " + resultEntry.errorCode());
}
}