当前位置: 首页>>代码示例>>Java>>正文


Java LambdaLogger类代码示例

本文整理汇总了Java中com.amazonaws.services.lambda.runtime.LambdaLogger的典型用法代码示例。如果您正苦于以下问题:Java LambdaLogger类的具体用法?Java LambdaLogger怎么用?Java LambdaLogger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LambdaLogger类属于com.amazonaws.services.lambda.runtime包,在下文中一共展示了LambdaLogger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleRequestShouldThrowException

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
@Test
public void handleRequestShouldThrowException() throws TemplateException, KeyOperationException, IOException {
    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage("Email");
    LinkGeneratorLambdaHandler handler = mock(LinkGeneratorLambdaHandler.class);
    doCallRealMethod().when(handler).handleRequest(any(), any());
    Exception ex = new TemplateException("Message", null);
    doThrow(ex).when(handler).getUploadPageUrlFromRequest(any(), any());
    
    Context context = mock(Context.class);
    LambdaLogger logger = mock(LambdaLogger.class);
    doNothing().when(logger).log(anyString());
    doReturn(logger).when(context).getLogger();
    
    handler.handleRequest(mock(LinkGeneratorRequest.class), context);
}
 
开发者ID:julianghionoiu,项目名称:tdl-auth,代码行数:17,代码来源:LinkGeneratorLambdaTest.java

示例2: handleRequestShouldReturnNotOkayOnException

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
@Test
public void handleRequestShouldReturnNotOkayOnException() throws IOException, TemplateException {
    Map<String, Object> input = new HashMap<>();
    input.put("email", "[email protected]");
    input.put("url", "http://www.example.com");

    MailLinkLambdaHandler handler = spy(new MailLinkLambdaHandler());
    Mailer mailer = mock(Mailer.class);
    doThrow(new IOException()).when(mailer).send();
    doReturn(mailer).when(handler).createMailer(anyString(), anyString());
    Context context = mock(Context.class);
    doReturn(mock(LambdaLogger.class)).when(context).getLogger();
    
    String result = handler.handleRequest(input, context);
    assertEquals(result, "NOT OK");
}
 
开发者ID:julianghionoiu,项目名称:tdl-auth,代码行数:17,代码来源:MailLinkLambdaHandlerTest.java

示例3: 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();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:24,代码来源:LambdaLock.java

示例4: createSnapshotFromTagName

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
public void createSnapshotFromTagName(TagNameRequest tagNameRequest, Context context) {

		LambdaLogger logger = context.getLogger();
		logger.log("create ebs snapshot from tag name Start. backup target[" + tagNameRequest + "]");

		String regionName = System.getenv("AWS_DEFAULT_REGION");
		AmazonEC2Async client = RegionUtils.getRegion(regionName).createClient(AmazonEC2AsyncClient.class,
				new DefaultAWSCredentialsProviderChain(), cc);

		try {
			List<Volume> volumes = describeBackupVolumes(client, tagNameRequest);

			for (Volume volume : volumes) {
				createSnapshot(volume.getVolumeId(), tagNameRequest.getGenerationCount(), context);
			}
		} finally {
			client.shutdown();
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:20,代码来源:EBSSnapshotFunction.java

示例5: 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;
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:25,代码来源:LambdaLock.java

示例6: appendRevvingSuffix

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
/**
 * Adds revving suffix to all filenames beneath a folder.
 * 
 * <p>Adds revving suffix to all filenames beneath a folder, recursing into subfolders.
 *    Only js and css files are revved.
 * 
 *    @param suffix the suffix to add to all filenames.
 *    @param startFolder the folder at root of tree within which to suffix files
 *    @param logger a CloudwatchLogs logger.
 * @throws IOException
 */
public static void appendRevvingSuffix(String suffix, Path startFolder, LambdaLogger logger)
    throws IOException {
  Files
      .walk(startFolder, FileVisitOption.FOLLOW_LINKS)
      .filter(Files::isRegularFile)
      .forEach(path -> {
        File file = path.toFile();
        if (file.isDirectory()) {
          return;
        }
        String absolutePath = file.getAbsolutePath();
        String fileExtension = FilenameUtils.getExtension(absolutePath);
        if (!fileExtension.equals("js") && !fileExtension.equals("css")) {
          // We rev only js and css
          return;
        }
        String suffixedName = FilenameUtils.getBaseName(absolutePath) + "_" + suffix + "."
            + fileExtension;
        File suffixedFile = new File(file.getParentFile(), suffixedName);
        file.renameTo(suffixedFile);
        logger.log("Appended suffix to file: " + absolutePath + ", giving: "
            + suffixedFile.getAbsolutePath());
      });
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:36,代码来源:FileUtils.java

示例7: getBookingPostRequestTemplate

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
String getBookingPostRequestTemplate(LambdaLogger logger) throws IOException {
  // This template transforms the url-encoded POST body to JSON for lambda
  logger.log("About to add request template to transform POST body to JSON");

  // / Get the mapping template from our resources
  String mappingTemplate = null;
  try (InputStream stream = GetBookingsLambda.class
      .getResourceAsStream("/squash/booking/lambdas/BookingPostMappingTemplate.vm")) {
    logger.log("Reading BookingPostMappingTemplate.vm from resources");
    mappingTemplate = CharStreams.toString(new InputStreamReader(stream, "UTF-8"));
    logger.log("Mapping template read from resources: " + mappingTemplate);
  } catch (IOException e) {
    logger.log("Exception caught reading mapping template from resources: " + e.getMessage());
    throw e;
  }

  return mappingTemplate;
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:19,代码来源:ApiGatewayCustomResourceLambda.java

示例8: addRolesToIdentityPool

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
void addRolesToIdentityPool(String unauthenticatedRoleName, String unauthenticatedRole,
    String authenticatedRoleName, String authenticatedRole, String identityPoolId,
    AmazonCognitoIdentity client, LambdaLogger logger) {
  // First update the roles to use the actual pool id in their conditions
  logger
      .log("Updating authenticated and unauthenticated roles to use the actual identity pool id: "
          + identityPoolId);
  AmazonIdentityManagement iamClient = AmazonIdentityManagementClientBuilder.standard().build();
  UpdateAssumeRolePolicyRequest updateAssumeRolePolicyRequest = new UpdateAssumeRolePolicyRequest();
  updateAssumeRolePolicyRequest.setRoleName(unauthenticatedRoleName);
  updateAssumeRolePolicyRequest.setPolicyDocument(getAssumeRolePolicyDocument(false,
      identityPoolId, logger));
  iamClient.updateAssumeRolePolicy(updateAssumeRolePolicyRequest);
  updateAssumeRolePolicyRequest.setRoleName(authenticatedRoleName);
  updateAssumeRolePolicyRequest.setPolicyDocument(getAssumeRolePolicyDocument(true,
      identityPoolId, logger));
  iamClient.updateAssumeRolePolicy(updateAssumeRolePolicyRequest);

  // And add the updated roles to the pool
  logger.log("Adding updated authenticated and unauthenticated roles to the identity pool");
  SetIdentityPoolRolesRequest setIdentityPoolRolesRequest = new SetIdentityPoolRolesRequest();
  setIdentityPoolRolesRequest.addRolesEntry("authenticated", authenticatedRole);
  setIdentityPoolRolesRequest.addRolesEntry("unauthenticated", unauthenticatedRole);
  setIdentityPoolRolesRequest.setIdentityPoolId(identityPoolId);
  client.setIdentityPoolRoles(setIdentityPoolRolesRequest);
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:27,代码来源:CognitoCustomResourceLambda.java

示例9: 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;
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:22,代码来源:CognitoCustomResourceLambda.java

示例10: 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();
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:18,代码来源:PutDeleteBookingRuleOrExclusionLambda.java

示例11: 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();
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:18,代码来源:PutDeleteBookingRuleOrExclusionLambda.java

示例12: 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;
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:30,代码来源:SnsEventHandler.java

示例13: getRuleManager

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
/**
 * Returns the {@link squash.booking.lambdas.core.IRuleManager}.
 */
protected IRuleManager getRuleManager(LambdaLogger logger) throws Exception {
  // Use a getter here so unit tests can substitute a mock manager
  if (!ruleManager.isPresent()) {
    ruleManager = Optional.of(new RuleManager());
    ruleManager.get().initialise(getBookingManager(logger), getLifecycleManager(logger), logger);
  }
  return ruleManager.get();
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:12,代码来源:ApplyBookingRulesLambda.java

示例14: initialise

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
@Override
public final void initialise(int maxNumberOfAttributes, LambdaLogger logger) throws Exception {

  if (initialised) {
    throw new IllegalStateException("The optimistic persister has already been initialised");
  }

  this.logger = logger;
  simpleDbDomainName = getEnvironmentVariable("SimpleDBDomainName");
  versionAttributeName = "VersionNumber";
  this.maxNumberOfAttributes = maxNumberOfAttributes;
  region = Region.getRegion(Regions.fromName(getEnvironmentVariable("AWS_REGION")));
  initialised = true;
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:15,代码来源:OptimisticPersister.java

示例15: createSnapshotFromVolumeIds

import com.amazonaws.services.lambda.runtime.LambdaLogger; //导入依赖的package包/类
public void createSnapshotFromVolumeIds(VolumeIdRequests volumeIdRequests, Context context) {

		LambdaLogger logger = context.getLogger();
		logger.log("create ebs snapshot from volumeids Start. backup target[" + volumeIdRequests + "]");

		for (VolumeIdRequest volumeIdRequest : volumeIdRequests.getVolumeIdRequests()) {
			createSnapshotFromVolumeId(volumeIdRequest, context);
		}
	}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:10,代码来源:EBSSnapshotFunction.java


注:本文中的com.amazonaws.services.lambda.runtime.LambdaLogger类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。