本文整理汇总了Java中com.amazonaws.services.lambda.runtime.Context.getFunctionName方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getFunctionName方法的具体用法?Java Context.getFunctionName怎么用?Java Context.getFunctionName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.lambda.runtime.Context
的用法示例。
在下文中一共展示了Context.getFunctionName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入方法依赖的package包/类
@Override
public Parameters handleRequest(S3Event event, Context context) {
context.getLogger()
.log("Input Function [" + context.getFunctionName() + "], S3Event [" + event.toJson().toString() + "]");
Parameters parameters = new Parameters(
event.getRecords().get(0).getS3().getBucket().getName(),
event.getRecords().get(0).getS3().getObject().getKey());
AWSStepFunctions client = AWSStepFunctionsClientBuilder.defaultClient();
ObjectMapper jsonMapper = new ObjectMapper();
StartExecutionRequest request = new StartExecutionRequest();
request.setStateMachineArn(System.getenv("STEP_MACHINE_ARN"));
try {
request.setInput(jsonMapper.writeValueAsString(parameters));
} catch (JsonProcessingException e) {
throw new AmazonServiceException("Error in ["+context.getFunctionName()+"]", e);
}
context.getLogger()
.log("Step Function [" + request.getStateMachineArn() + "] will be called with [" + request.getInput() + "]");
StartExecutionResult result = client.startExecution(request);
context.getLogger()
.log("Output Function [" + context.getFunctionName() + "], Result [" + result.toString() + "]");
return parameters;
}
示例2: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入方法依赖的package包/类
@Override
public Parameters handleRequest(Parameters parameters, Context context) {
context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
try {
// Create an empty Mime message and start populating it
Session session = Session.getDefaultInstance(new Properties());
MimeMessage message = new MimeMessage(session);
message.setSubject(EMAIL_SUBJECT, "UTF-8");
message.setFrom(new InternetAddress(System.getenv("EMAIL_FROM")));
message.setReplyTo(new Address[] { new InternetAddress(System.getenv("EMAIL_FROM")) });
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(System.getenv("EMAIL_RECIPIENT")));
MimeBodyPart wrap = new MimeBodyPart();
MimeMultipart cover = new MimeMultipart("alternative");
MimeBodyPart html = new MimeBodyPart();
cover.addBodyPart(html);
wrap.setContent(cover);
MimeMultipart content = new MimeMultipart("related");
message.setContent(content);
content.addBodyPart(wrap);
// Create an S3 URL reference to the snapshot that will be attached to this email
URL attachmentURL = createSignedURL(parameters.getS3Bucket(), parameters.getS3Key());
StringBuilder sb = new StringBuilder();
String id = UUID.randomUUID().toString();
sb.append("<img src=\"cid:");
sb.append(id);
sb.append("\" alt=\"ATTACHMENT\"/>\n");
// Add the attachment as a part of the message body
MimeBodyPart attachment = new MimeBodyPart();
DataSource fds = new URLDataSource(attachmentURL);
attachment.setDataHandler(new DataHandler(fds));
attachment.setContentID("<" + id + ">");
attachment.setDisposition(BodyPart.ATTACHMENT);
attachment.setFileName(fds.getName());
content.addBodyPart(attachment);
// Pretty print the Rekognition Labels as part of the Emails HTML content
String prettyPrintLabels = parameters.getRekognitionLabels().toString();
prettyPrintLabels = prettyPrintLabels.replace("{", "").replace("}", "");
prettyPrintLabels = prettyPrintLabels.replace(",", "<br>");
html.setContent("<html><body><h2>Uploaded Filename : " + parameters.getS3Key().replace("upload/", "") +
"</h2><p><b>Detected Labels/Confidence</b><br><br>" + prettyPrintLabels + "</p>"+sb+"</body></html>", "text/html");
// Convert the JavaMail message into a raw email request for sending via SES
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
message.writeTo(outputStream);
RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);
// Send the email using the AWS SES Service
AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.defaultClient();
client.sendRawEmail(rawEmailRequest);
} catch (MessagingException | IOException e) {
// Convert Checked Exceptions to RuntimeExceptions to ensure that
// they get picked up by the Step Function infrastructure
throw new AmazonServiceException("Error in ["+context.getFunctionName()+"]", e);
}
context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");
return parameters;
}