本文整理汇总了Java中com.amazonaws.services.lambda.runtime.LambdaLogger.log方法的典型用法代码示例。如果您正苦于以下问题:Java LambdaLogger.log方法的具体用法?Java LambdaLogger.log怎么用?Java LambdaLogger.log使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.lambda.runtime.LambdaLogger
的用法示例。
在下文中一共展示了LambdaLogger.log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: gzip
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
/**
* GZIPs data in memory.
*
* <p>Returns gzip-ed version of an array.
*
* @param dataToZip the byte array to gzip.
* @param logger a CloudwatchLogs logger.
* @throws Exception
*/
public static byte[] gzip(byte[] dataToZip, LambdaLogger logger) throws Exception {
logger.log("About to zip byte[].");
try {
try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream(dataToZip.length)) {
try (GZIPOutputStream zipStream = new GZIPOutputStream(byteStream)) {
zipStream.write(dataToZip);
}
logger.log("Zipped byte[]");
return byteStream.toByteArray();
}
} catch (Exception e) {
logger.log("Caught exception whilst zipping byte[]: " + e.getMessage());
throw e;
}
}
示例2: backupBookingsAndBookingRules
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
/**
* Backs up all bookings and booking rules in the database.
*/
public BackupBookingsAndBookingRulesLambdaResponse backupBookingsAndBookingRules(
BackupBookingsAndBookingRulesLambdaRequest request, Context context) throws Exception {
LambdaLogger logger = context.getLogger();
logger.log("Backup bookings and booking rules for request: " + request.toString());
// Backup all bookings and booking rules
ImmutablePair<List<Booking>, List<BookingRule>> bookingAndRules = getBackupManager(logger)
.backupAllBookingsAndBookingRules();
logger.log("Backed up bookings and booking rules");
BackupBookingsAndBookingRulesLambdaResponse response = new BackupBookingsAndBookingRulesLambdaResponse();
response.setBookings(bookingAndRules.left);
response.setBookingRules(bookingAndRules.right);
response.setClearBeforeRestore(true);
return response;
}
示例3: lock
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
public boolean lock(String key, int expiredIntervalMillis, Context context) {
LambdaLogger logger = context.getLogger();
long currentTimeMillis = System.currentTimeMillis();
String functionName = context.getFunctionName();
// Create a record if it does not exist
if (createItemIfNotExists(key, currentTimeMillis, context)) {
logger.log("[SUCCESS]It won the lock. functionName[" + functionName + "] key[" + key + "]");
return true;
}
// To update, if the lock out of period
if (updateItem(key, currentTimeMillis, expiredIntervalMillis, context)) {
logger.log("[SUCCESS]It won the lock. functionName[" + functionName + "] key[" + key + "]");
return true;
} else {
context.getLogger().log(
"[ERROR]You can not acquire a lock because it does not have one second has elapsed from the last lock acquisition Time.");
return false;
}
}
示例4: createItemIfNotExists
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
boolean createItemIfNotExists(String key, long currentTimeMillis, Context context) {
LambdaLogger logger = context.getLogger();
AmazonDynamoDB client = createDynamoDBClient(cc);
String functionName = context.getFunctionName();
try {
// Create a record if it does not exist
PutItemRequest req = new PutItemRequest().withTableName(TABLE_NAME)
.addItemEntry(COL_FUNCTION_NAME, new AttributeValue(functionName))
.addItemEntry(COL_KEY, new AttributeValue(key))
.addItemEntry(COL_CREATED_TIME, new AttributeValue().withN(Long.toString(currentTimeMillis)))
.addExpectedEntry(COL_FUNCTION_NAME, new ExpectedAttributeValue().withExists(false))
.addExpectedEntry(COL_KEY, new ExpectedAttributeValue().withExists(false));
client.putItem(req);
return true;
} catch (ConditionalCheckFailedException e) {
logger.log("Record exsited. functionName[" + functionName + "] key[" + key + "]");
return false;
} finally {
client.shutdown();
}
}
示例5: createBookingRuleExclusion
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
private PutDeleteBookingRuleOrExclusionLambdaResponse createBookingRuleExclusion(
PutDeleteBookingRuleOrExclusionLambdaRequest request, Context context) throws Exception {
LambdaLogger logger = context.getLogger();
logger.log("About to create booking rule exclusion for request: " + request.toString());
IRuleManager ruleManager = getRuleManager(logger);
Optional<BookingRule> updatedRule = ruleManager.addRuleExclusion(request.getDateToExclude(),
request.getBookingRule(), true);
logger.log("Created booking rule exclusion");
// Backup this updated booking rule - if a change was necessary
if (updatedRule.isPresent()) {
getBackupManager(logger).backupSingleBookingRule(updatedRule.get(), true);
}
return new PutDeleteBookingRuleOrExclusionLambdaResponse();
}
示例6: deleteBookingRuleExclusion
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
private PutDeleteBookingRuleOrExclusionLambdaResponse deleteBookingRuleExclusion(
PutDeleteBookingRuleOrExclusionLambdaRequest request, Context context) throws Exception {
LambdaLogger logger = context.getLogger();
logger.log("About to delete booking rule exclusion for request: " + request.toString());
IRuleManager ruleManager = getRuleManager(logger);
Optional<BookingRule> updatedRule = ruleManager.deleteRuleExclusion(request.getDateToExclude(),
request.getBookingRule(), true);
logger.log("Deleted booking rule exclusion");
// Backup this updated booking rule - if a change was necessary
if (updatedRule.isPresent()) {
getBackupManager(logger).backupSingleBookingRule(updatedRule.get(), true);
}
return new PutDeleteBookingRuleOrExclusionLambdaResponse();
}
示例7: getAssumeRolePolicyDocument
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
String getAssumeRolePolicyDocument(Boolean isAuthenticatedRole, String identityPoolId,
LambdaLogger logger) {
// N.B. We have to add this here rather than in the CloudFormation
// template since we don't know the identity pool id until here.
String amrLine = isAuthenticatedRole ? " \"cognito-identity.amazonaws.com:amr\": \"authenticated\"\n"
: " \"cognito-identity.amazonaws.com:amr\": \"unauthenticated\"\n";
String assumeRolePolicyDocument = "{" + " \"Version\" : \"2012-10-17\",\n"
+ " \"Statement\": [ {\n" + " \"Effect\": \"Allow\",\n" + " \"Principal\": {\n"
+ " \"Federated\": \"cognito-identity.amazonaws.com\"\n" + " },\n"
+ " \"Action\": \"sts:AssumeRoleWithWebIdentity\",\n" + " \"Condition\": {\n"
+ " \"StringEquals\": {\n" + " \"cognito-identity.amazonaws.com:aud\":\n"
+ " \"" + identityPoolId + "\"\n" + " },\n"
+ " \"ForAnyValue:StringLike\": {\n" + amrLine + " }\n" + " }\n"
+ " }]\n" + " }";
logger.log("Assume role policy document: ");
logger.log(assumeRolePolicyDocument);
return assumeRolePolicyDocument;
}
示例8: handleRequest
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
@Override
public Object handleRequest(SNSEvent request, Context context) {
final LambdaLogger logger = context.getLogger();
final String message = request.getRecords().get(0).getSNS().getMessage();
logger.log("Handle message '" + message + "'");
final List<Recipient> recipients = new CloudNoticeDAO(false)
.getRecipients();
final List<String> emailAddresses = recipients.stream()
.filter(r -> "email".equalsIgnoreCase(r.getType()))
.map(r -> r.getAddress())
.collect(Collectors.toList());
final List<String> phoneNumbers = recipients.stream()
.filter(r -> "sms".equalsIgnoreCase(r.getType()))
.map(r -> r.getAddress())
.collect(Collectors.toList());
final SesClient sesClient = new SesClient();
final SnsClient snsClient = new SnsClient();
sesClient.sendEmails(emailAddresses, "[email protected]",
"Cloud Notification", message);
snsClient.sendTextMessages(phoneNumbers, message);
sesClient.shutdown();
snsClient.shutdown();
logger.log("Message handling complete.");
return null;
}
示例9: getPoolIdsFromPhysicalResourceId
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
Map<String, String> getPoolIdsFromPhysicalResourceId(String physicalResourceId,
LambdaLogger logger) {
// Extract identity and user pool ids from the physical resource id
String identityPoolId = physicalResourceId.substring("Identity pool id: ".length(),
physicalResourceId.indexOf(", User pool id: "));
logger.log("Using identity pool id: " + identityPoolId);
String userPoolIdMarker = ", User pool id: ";
String userPoolId = physicalResourceId.substring(physicalResourceId.indexOf(userPoolIdMarker)
+ userPoolIdMarker.length(), physicalResourceId.length());
logger.log("Using user pool id: " + userPoolId);
Map<String, String> poolIds = new HashMap<>();
poolIds.put("IdentityPoolId", identityPoolId);
poolIds.put("UserPoolId", userPoolId);
return poolIds;
}
示例10: getEnvironmentVariable
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
/**
* Returns a named environment variable.
* @throws Exception
*/
protected String getEnvironmentVariable(String variableName, LambdaLogger logger)
throws Exception {
// Use a getter here so unit tests can substitute a mock value.
// We get the value from an environment variable so that CloudFormation can
// set the actual value when the stack is created.
String environmentVariable = System.getenv(variableName);
if (environmentVariable == null) {
logger.log("Environment variable: " + variableName + " is not defined, so throwing.");
throw new Exception("Environment variable: " + variableName + " should be defined.");
}
return environmentVariable;
}
示例11: restoreBookingsAndBookingRules
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
/**
* Restore bookings and booking rules to the database.
*
* @param request containing bookings and booking rules to restore.
* @return response.
*/
public RestoreBookingsAndBookingRulesLambdaResponse restoreBookingsAndBookingRules(
RestoreBookingsAndBookingRulesLambdaRequest request, Context context) throws Exception {
LambdaLogger logger = context.getLogger();
logger.log("Restoring bookings and booking rules for request: " + request.toString());
getBackupManager(logger).restoreAllBookingsAndBookingRules(request.getBookings(),
request.getBookingRules(), request.getClearBeforeRestore());
logger.log("Finished restoring bookings and booking rules");
return new RestoreBookingsAndBookingRulesLambdaResponse();
}
示例12: deleteBookingRule
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
private PutDeleteBookingRuleOrExclusionLambdaResponse deleteBookingRule(
PutDeleteBookingRuleOrExclusionLambdaRequest request, Context context) throws Exception {
LambdaLogger logger = context.getLogger();
logger.log("About to delete booking rule for request: " + request.toString());
IRuleManager ruleManager = getRuleManager(logger);
ruleManager.deleteRule(request.getBookingRule(), true);
// Backup this booking rule deletion
getBackupManager(logger).backupSingleBookingRule(request.getBookingRule(), false);
return new PutDeleteBookingRuleOrExclusionLambdaResponse();
}
示例13: copySnapshotFromSnapshotId
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
public void copySnapshotFromSnapshotId(SnapshotIdRequest snapshotIdRequest, Context context) {
LambdaLogger logger = context.getLogger();
logger.log("copy ebs snapshot from snapshot id Start. backup target[" + snapshotIdRequest + "]");
copySnapshot(snapshotIdRequest.getSourceSnapshotId(), snapshotIdRequest.getDestinationRegion(),
snapshotIdRequest.getGenerationCount(), context);
}
示例14: logAmazonServiceException
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
/**
* Logs an AmazonServiceException to a lambda logger.
*/
public static void logAmazonServiceException(AmazonServiceException ase, LambdaLogger logger) {
logger.log("Caught an AmazonServiceException, which " + "means the request made it "
+ "to AWS, but was rejected with an error response " + "for some reason.");
logger.log("Error Message: " + ase.getMessage());
logger.log("HTTP Status Code: " + ase.getStatusCode());
logger.log("AWS Error Code: " + ase.getErrorCode());
logger.log("Error Type: " + ase.getErrorType());
logger.log("Request ID: " + ase.getRequestId());
}
示例15: logAmazonClientException
import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入方法依赖的package包/类
/**
* Logs an AmazonClientException to a lambda logger.
*/
public static void logAmazonClientException(AmazonClientException ace, LambdaLogger logger) {
logger.log("Caught an AmazonClientException, which means " + "the client encountered "
+ "an internal error while trying to " + "communicate with AWS, "
+ "such as not being able to access the network.");
logger.log("Error Message: " + ace.getMessage());
}