本文整理汇总了Java中com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord方法的典型用法代码示例。如果您正苦于以下问题:Java SNSEvent.SNSRecord方法的具体用法?Java SNSEvent.SNSRecord怎么用?Java SNSEvent.SNSRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.lambda.runtime.events.SNSEvent
的用法示例。
在下文中一共展示了SNSEvent.SNSRecord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSnsEvent
import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入方法依赖的package包/类
private SNSEvent createSnsEvent(final String githubEvent) {
SNSEvent.SNS sns = new SNSEvent.SNS();
sns.setMessageAttributes(new HashMap<String, SNSEvent.MessageAttribute>(1, 1) {
{
SNSEvent.MessageAttribute attr = new SNSEvent.MessageAttribute();
attr.setValue(githubEvent);
put("X-Github-Event", attr);
}
});
try (InputStream is = getClass().getResourceAsStream("/github-push-payload.json")) {
sns.setMessage(IOUtils.toString(is));
}
catch (IOException e) {
throw new IllegalArgumentException(e);
}
SNSEvent.SNSRecord record = new SNSEvent.SNSRecord();
record.setSns(sns);
SNSEvent snsEvent = new SNSEvent();
snsEvent.setRecords(Collections.singletonList(record));
return snsEvent;
}
示例2: handleRequest
import com.amazonaws.services.lambda.runtime.events.SNSEvent; //导入方法依赖的package包/类
public Integer handleRequest(SNSEvent event, Context context) {
try {
// SNS Events could be possible more than one even if this looks a bit unusual for the deploy case.
for (SNSEvent.SNSRecord record : event.getRecords()) {
SNSEvent.SNS sns = record.getSNS();
// Check SNS header for event type.
SNSEvent.MessageAttribute attr = sns.getMessageAttributes().get(X_GITHUB_EVENT);
// Only watch pushes to master.
if (EVENT_PUSH.equalsIgnoreCase(attr.getValue())) {
PushPayload value = MAPPER.readValue(sns.getMessage(), PushPayload.class);
if (config.isWatchedBranch(new Branch(value.getRef()))) {
LOG.info(format("Processing '%s' on '%s': '%s'", attr.getValue(), value.getRef(), value.getHeadCommit().getId()));
switch (worker.call()) {
case SUCCESS:
return HttpStatus.SC_OK;
case FAILED:
return HttpStatus.SC_BAD_REQUEST;
}
}
// Different branch was found.
else {
LOG.info(format("Push received for: '%s'", value.getRef()));
}
}
// Different event was found.
else {
LOG.info(format("Event was: '%s'", attr.getValue()));
}
}
}
catch (Exception e) {
LOG.error(e.getMessage(), e);
return HttpStatus.SC_INTERNAL_SERVER_ERROR;
}
return HttpStatus.SC_BAD_REQUEST;
}