本文整理汇总了Java中com.amazonaws.services.lambda.runtime.Context类的典型用法代码示例。如果您正苦于以下问题:Java Context类的具体用法?Java Context怎么用?Java Context使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于com.amazonaws.services.lambda.runtime包,在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequestShouldThrowException
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的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);
}
示例2: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
/**
* This is a handler method called by the AWS Lambda runtime
*/
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
// Lambda function is allowed write access to /tmp only
System.setProperty("vertx.cacheDirBase", "/tmp/.vertx");
Vertx vertx = Vertx.vertx();
router = Router.router(vertx);
router.route().handler(rc -> {
LocalDateTime now = LocalDateTime.now();
rc.response().putHeader("content-type", "text/html").end("Hello from Lambda at " + now);
});
// create a LambdaServer which will process a single HTTP request
LambdaServer server = new LambdaServer(vertx, context, input, output);
// trigger the HTTP request processing
server.requestHandler(this::handleRequest).listen();
// block the main thread until the request has been fully processed
waitForResponseEnd();
}
示例3: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
public String handleRequest(ReducerWrapperInfo reducerWrapperInfo, Context context) {
try {
this.reducerWrapperInfo = reducerWrapperInfo;
this.reducerLogic = instantiateReducerClass();
this.jobInfo = this.reducerWrapperInfo.getJobInfo();
this.jobId = this.jobInfo.getJobId();
List<ObjectInfoSimple> batch = reducerWrapperInfo.getBatch();
String reduceResult = processBatch(batch);
if (this.reducerWrapperInfo.isLast())
storeFinalResult(reduceResult);
else
storeIntermediateResult(reduceResult);
} catch (Exception e) {
throw new RuntimeException(e);
}
return IGNORED_RETURN_VALUE;
}
示例4: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
public String handleRequest(ReducersDriverInfo reducersDriverInfo, Context context) {
try {
this.reducersDriverInfo = reducersDriverInfo;
this.jobInfo = this.reducersDriverInfo.getJobInfo();
this.jobId = this.jobInfo.getJobId();
launchReducers(reducersDriverInfo.getStep());
} catch (Exception e) {
throw new RuntimeException(e);
}
return IGNORED_RETURN_VALUE;
}
示例5: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
public Void handleRequest(S3Event s3Event, Context context) {
Collection<Partition> requiredPartitions = new HashSet<>();
TableService tableService = new TableService();
for (S3EventNotification.S3EventNotificationRecord record : s3Event.getRecords()) {
String bucket = record.getS3().getBucket().getName();
String key = record.getS3().getObject().getKey();
System.out.printf("S3 event [Event: %s, Bucket: %s, Key: %s]%n", record.getEventName(), bucket, key);
S3Object s3Object = new S3Object(bucket, key);
if (s3Object.hasDateTimeKey()) {
requiredPartitions.add(partitionConfig.createPartitionFor(s3Object));
}
}
if (!requiredPartitions.isEmpty()) {
Collection<Partition> missingPartitions = determineMissingPartitions(
partitionConfig.tableName(),
requiredPartitions,
tableService);
tableService.addPartitions(partitionConfig.tableName(), missingPartitions);
}
return null;
}
示例6: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
public Void handleRequest(S3Event s3Event, Context context) {
Collection<Partition> partitionsToRemove = new HashSet<>();
TableService tableService = new TableService();
for (S3EventNotification.S3EventNotificationRecord record : s3Event.getRecords()) {
String bucket = record.getS3().getBucket().getName();
String key = record.getS3().getObject().getKey();
System.out.printf("S3 event [Event: %s, Bucket: %s, Key: %s]%n", record.getEventName(), bucket, key);
S3Object s3Object = new S3Object(bucket, key);
if (s3Object.hasDateTimeKey()) {
partitionsToRemove.add(partitionConfig.createPartitionFor(s3Object));
}
}
if (!partitionsToRemove.isEmpty()) {
tableService.removePartitions(
partitionConfig.tableName(),
partitionsToRemove.stream().map(Partition::spec).collect(Collectors.toList()));
}
return null;
}
示例7: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
public Void handleRequest(S3Event s3Event, Context context){
Collection<Partition>requiredPartitions = new HashSet<>();
TableService tableService = new TableService();
DynamoDB dynamoDBClient=new DynamoDB(new AmazonDynamoDBClient(new EnvironmentVariableCredentialsProvider()));
for(S3EventNotification.S3EventNotificationRecord record:s3Event.getRecords()){
String bucket=record.getS3().getBucket().getName();
String key=record.getS3().getObject().getKey();
System.out.printf("S3event[Event:%s,Bucket:%s,Key:%s]%n",record.getEventName(),bucket,key);
S3Object s3Object=new S3Object(bucket,key);
if(s3Object.hasDateTimeKey()){
Partition partition = partitionConfig.createPartitionFor(s3Object);
//Check if the partition exists in DynamoDBtable, if not add the partition details to the table, skip otherwise
if (tryAddMissingPartition(partitionConfig.dynamoDBTableName(), dynamoDBClient, partition)) {
requiredPartitions.add(partition);
}
}
}
if(!requiredPartitions.isEmpty()){
tableService.addPartitions(partitionConfig.tableName(),requiredPartitions, true);
}
return null;
}
开发者ID:awslabs,项目名称:serverless-cf-analysis,代码行数:33,代码来源:CreateAthenaPartitionsBasedOnS3EventWithDDB.java
示例8: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
Collection<String> partitionsToRemove = new HashSet<>();
DateTime expiryThreshold = partitionConfig.partitionType().roundDownTimeUnit(clock.now())
.minus(expirationConfig.expiresAfterMillis());
Collection<String> existingPartitions = tableService.getExistingPartitions(partitionConfig.tableName());
for (String existingPartition : existingPartitions) {
DateTime partitionDateTime = partitionConfig.partitionType().roundDownTimeUnit(
DateTime.parse(existingPartition, DATE_TIME_PATTERN));
if (hasExpired(partitionDateTime, expiryThreshold)) {
partitionsToRemove.add(existingPartition);
}
}
if (!partitionsToRemove.isEmpty()) {
tableService.removePartitions(partitionConfig.tableName(), partitionsToRemove);
}
}
示例9: setUp
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
context = mock(Context.class);
when(context.getLogger()).thenReturn(System.out::println);
handler = new AuthLambdaHandler(TEST_AWS_REGION, TEST_JWT_KEY_ARN, TEST_VIDEO_STORAGE_BUCKET,
TEST_USER_ACCESS_KEY_ID, TEST_USER_SECRET_ACCESS_KEY);
AWSKMS kmsClient = AWSKMSClientBuilder.standard()
.withRegion(TEST_AWS_REGION)
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(TEST_USER_ACCESS_KEY_ID, TEST_USER_SECRET_ACCESS_KEY))
)
.build();
kmsEncrypt = new KMSEncrypt(kmsClient, TEST_JWT_KEY_ARN);
}
示例10: shouldFailOnOtherError
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Test
public void shouldFailOnOtherError() throws Exception {
// Given
Context context = mock(Context.class);
SNSEvent snsEvent = createSnsEvent("push");
doThrow(new IllegalArgumentException("Expected test exception")).when(config).isWatchedBranch(any());
// When
Integer response = uut.handleRequest(snsEvent, context);
// Then
assertThat(response, is(HttpStatus.SC_INTERNAL_SERVER_ERROR));
verify(config, times(1)).isWatchedBranch(any());
verify(worker, times(0)).call();
}
示例11: testScheduledEventHandlerSuccessfully
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testScheduledEventHandlerSuccessfully() throws Exception {
new Expectations(TestScheduledAction.class) {
{
new TestScheduledAction().handle((EventActionRequest<EmptyActionBody>)any, (Context)any);
times = 1;
}
};
ScheduledEventResult result = handler.handleRequest(event, mockContext);
assertEquals(1, result.getSuccessItems().size());
assertEquals(0, result.getFailureItems().size());
assertEquals(0, result.getSkippedItems().size());
}
示例12: handleRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
public Object handleRequest(Map<String, Object> input, Context context) {
LexRequest lexRequest = LexRequestFactory.createLexRequest(input);
String content = String.format("Request came from the bot: %s, Department: %s;" +
"You ordered: %s %s of %s",
lexRequest.getBotName(),
lexRequest.getDepartmentName(),
lexRequest.getAmount(),
lexRequest.getUnit(),
lexRequest.getProduct()
);
Message message = new Message("PlainText", content);
DialogAction dialogAction = new DialogAction("Close", "Fulfilled", message);
return new LexRespond(dialogAction);
}
示例13: handleEvent
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Override
protected S3EventResult handleEvent(S3EventNotification event, Context context) {
AwsEventRequest request = readEvent(event);
S3EventResult result = new S3EventResult();
AwsEventResponse res = actionRouterHandle(request, context);
if (res.isSuccessful()) {
result.addSuccessItem(request);
} else {
logger.error("Failed processing S3Event", res.getCause());
result.addFailureItem(request);
}
return result;
}
示例14: testTradeHandler
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
@Test
public void testTradeHandler() {
try {
TradeServiceRequestHandler tradeServiceRequestHandler = new TradeServiceRequestHandler();
Context ctx = createContext();
List<DisplayMotTestItem> output = tradeServiceRequestHandler.getTradeMotTestsLegacy(input, ctx);
if (output != null) {
System.out.println(output.toString());
}
} catch (TradeException e) {
e.printStackTrace();
}
}
示例15: handleDebugRequest
import com.amazonaws.services.lambda.runtime.Context; //导入依赖的package包/类
private void handleDebugRequest(Map<String, Object> input, OutputStream outputStream, Context context)
throws IOException {
Map<String, Object> responseJson = new LinkedHashMap<>();
try {
responseJson.put("statusCode", 200);
responseJson.put("body", MAPPER.writeValueAsString(input));
} catch (Exception pex) {
responseJson.put("statusCode", "500");
responseJson.put("exception", pex);
}
MAPPER.writeValue(outputStream, responseJson);
}