• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java InvokeResult类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testInvokeLambdaFunctionAsynchronous

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testInvokeLambdaFunctionAsynchronous() throws Exception {
    InvokeConfig invokeConfig = new InvokeConfig("function", "{\"key1\": \"value1\"}", false, null);

    when(awsLambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(new InvokeResult());

    String result = lambdaInvokeService.invokeLambdaFunction(invokeConfig);

    verify(awsLambdaClient, times(1)).invoke(invokeRequestArg.capture());
    InvokeRequest invokeRequest = invokeRequestArg.getValue();
    assertEquals("function", invokeRequest.getFunctionName());
    assertEquals("{\"key1\": \"value1\"}", new String(invokeRequest.getPayload().array(), Charset.forName("UTF-8")));
    assertEquals(InvocationType.Event.toString(), invokeRequest.getInvocationType());
    verify(jenkinsLogger).log(eq("Lambda invoke request:%n%s%nPayload:%n%s%n"), anyVararg());
    verify(jenkinsLogger).log(eq("Lambda invoke response:%n%s%nPayload:%n%s%n"), anyVararg());
    assertEquals("", result);
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:19,代码来源:LambdaInvokeServiceTest.java


示例2: translate

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
public String translate(final String testPhrase, final String language) {
    final Map<String, Slot> slots = new HashMap<>();
    slots.put("termA", Slot.builder().withName("termA").withValue(testPhrase).build());
    slots.put("termB", Slot.builder().withName("termB").build());
    slots.put("language", Slot.builder().withName("language").withValue(language).build());
    final SpeechletRequestEnvelope envelope = givenIntentSpeechletRequestEnvelope("Translate", slots);
    final ObjectMapper mapper = new ObjectMapper();
    String response = null;
    try {
        final AWSLambdaClient awsLambda = new AWSLambdaClient();
        final InvokeRequest invokeRequest = new InvokeRequest()
                .withInvocationType(InvocationType.RequestResponse)
                .withFunctionName(lambdaName)
                .withPayload(mapper.writeValueAsString(envelope));
        final InvokeResult invokeResult = awsLambda.invoke(invokeRequest);
        response = new String(invokeResult.getPayload().array());
    } catch (JsonProcessingException e) {
        log.error(e.getMessage());
    }
    return response;
}
 
开发者ID:KayLerch,项目名称:alexa-meets-polly,代码行数:22,代码来源:SkillClient.java


示例3: testInvokeLambdaFunctionAsynchronousError

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testInvokeLambdaFunctionAsynchronousError() throws Exception {
    InvokeConfig invokeConfig = new InvokeConfig("function", "{\"key1\": \"value1\"}", false, null);

    when(awsLambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(new InvokeResult().withFunctionError("Handled"));

    try {
        lambdaInvokeService.invokeLambdaFunction(invokeConfig);
        fail("Should fail with LambdaInvokeException");
    } catch (LambdaInvokeException lie){
        assertEquals("Function returned error of type: Handled", lie.getMessage());
    }

    verify(awsLambdaClient, times(1)).invoke(invokeRequestArg.capture());
    InvokeRequest invokeRequest = invokeRequestArg.getValue();
    assertEquals("function", invokeRequest.getFunctionName());
    assertEquals("{\"key1\": \"value1\"}", new String(invokeRequest.getPayload().array(), Charset.forName("UTF-8")));
    assertEquals(InvocationType.Event.toString(), invokeRequest.getInvocationType());
    verify(jenkinsLogger).log(eq("Lambda invoke request:%n%s%nPayload:%n%s%n"), anyVararg());
    verify(jenkinsLogger).log(eq("Lambda invoke response:%n%s%nPayload:%n%s%n"), anyVararg());
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:23,代码来源:LambdaInvokeServiceTest.java


示例4: testLambdaInvokeSubsegmentContainsFunctionName

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testLambdaInvokeSubsegmentContainsFunctionName() {
    // Setup test
    AWSLambda lambda = AWSLambdaClientBuilder.standard().withRequestHandlers(new TracingHandler()).withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))).build();

    AmazonHttpClient amazonHttpClient = new AmazonHttpClient(new ClientConfiguration());
    ConnectionManagerAwareHttpClient apacheHttpClient = Mockito.mock(ConnectionManagerAwareHttpClient.class);
    HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    BasicHttpEntity responseBody = new BasicHttpEntity();
    responseBody.setContent(new ByteArrayInputStream("null".getBytes(StandardCharsets.UTF_8))); // Lambda returns "null" on successful fn. with no return value
    httpResponse.setEntity(responseBody);

    try {
        Mockito.doReturn(httpResponse).when(apacheHttpClient).execute(Mockito.any(HttpUriRequest.class), Mockito.any(HttpContext.class));
    } catch (IOException e) { }

    Whitebox.setInternalState(amazonHttpClient, "httpClient", apacheHttpClient);
    Whitebox.setInternalState(lambda, "client", amazonHttpClient);

    // Test logic
    Segment segment = AWSXRay.beginSegment("test");

    InvokeRequest request = new InvokeRequest();
    request.setFunctionName("testFunctionName");
    InvokeResult r = lambda.invoke(request);
    System.out.println(r.getStatusCode());
    System.out.println(r);

    Assert.assertEquals(1, segment.getSubsegments().size());
    Assert.assertEquals("Invoke", segment.getSubsegments().get(0).getAws().get("operation"));
    System.out.println(segment.getSubsegments().get(0).getAws());
    Assert.assertEquals("testFunctionName", segment.getSubsegments().get(0).getAws().get("function_name"));
}
 
开发者ID:aws,项目名称:aws-xray-sdk-java,代码行数:34,代码来源:TracingHandlerTest.java


示例5: fire

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
public Optional<AlexaResponse> fire(AlexaRequest request, String payload) {
    final InvocationType invocationType = request.expectsResponse() ? InvocationType.RequestResponse : InvocationType.Event;
    final InvokeRequest invokeRequest = new InvokeRequest()
            .withInvocationType(invocationType)
            .withFunctionName(lambdaFunctionName)
            .withPayload(payload);
    log.info(String.format("->[INFO] Invoke lambda function '%s'.", lambdaFunctionName));
    log.debug(String.format("->[INFO] with request payload '%s'.", payload));
    final InvokeResult invokeResult = lambdaClient.invoke(invokeRequest);
    return invocationType.equals(InvocationType.RequestResponse) ?
            Optional.of(new AlexaResponse(request, payload, new String(invokeResult.getPayload().array()))) : Optional.empty();
}
 
开发者ID:KayLerch,项目名称:alexa-skills-kit-tester-java,代码行数:13,代码来源:AlexaLambdaEndpoint.java


示例6: forceLambdaToUpdateSgs

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
/**
 * Forces the lambda to run and sync the IPs for CloudFront to be white listed on the origin elb
 */
private void forceLambdaToUpdateSgs(String arn) {
    String json;
    try {
         json = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("aws-ip-space-change-sns-sample-event.json"));
    } catch (IOException e) {
        String msg = "Failed to load mock sns message, to force Lambda first run";
        logger.error(msg, e);
        throw new RuntimeException(msg, e);
    }
    // this will fail
    InvokeResult result = awsLambda.invoke(new InvokeRequest().withFunctionName(arn).withPayload(String.format(json, BAD_HASH)).withLogType(LogType.Tail));
    // collect the error so we can parse it for the latest hash
    String log = new String(Base64.getDecoder().decode(result.getLogResult()), Charset.forName("UTF-8"));
    Pattern pattern = Pattern.compile("MD5 Mismatch: got\\s(.*?)\\sexp.*?");
    Matcher matcher = pattern.matcher(log);
    boolean matched = matcher.find();
    if (! matched) {
        throw new RuntimeException("failed to extract hash from: " + log);
    }

    String realHash = matcher.group(1);
    result = awsLambda.invoke(new InvokeRequest().withFunctionName(arn).withPayload(String.format(json, realHash)).withLogType(LogType.Tail));

    logger.info("Forcing the Lambda to run and update Security Groups");
    logger.info(new String(result.getPayload().array(), Charset.forName("UTF-8")));
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:30,代码来源:CreateCloudFrontSecurityGroupUpdaterLambdaOperation.java


示例7: invokeLambdaFunction

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
/**
 * Synchronously or asynchronously invokes an AWS Lambda function.
 * If synchronously invoked, the AWS Lambda log is collected and the response payload is returned
 * @param invokeConfig AWS Lambda invocation configuration
 * @return response payload
 */
public String invokeLambdaFunction(InvokeConfig invokeConfig) throws LambdaInvokeException {
    InvokeRequest invokeRequest = new InvokeRequest()
            .withFunctionName(invokeConfig.getFunctionName())
            .withPayload(invokeConfig.getPayload());

    if(invokeConfig.isSynchronous()){
        invokeRequest
                .withInvocationType(InvocationType.RequestResponse)
                .withLogType(LogType.Tail);
    } else {
        invokeRequest
                .withInvocationType(InvocationType.Event);
    }
    logger.log("Lambda invoke request:%n%s%nPayload:%n%s%n", invokeRequest.toString(), invokeConfig.getPayload());

    InvokeResult invokeResult = client.invoke(invokeRequest);
    String payload = "";
    if(invokeResult.getPayload() != null){
        payload = new String(invokeResult.getPayload().array(), Charset.forName("UTF-8"));
    }
    logger.log("Lambda invoke response:%n%s%nPayload:%n%s%n", invokeResult.toString(), payload);

    if(invokeResult.getLogResult() != null){
        logger.log("Log:%n%s%n", new String(Base64.decode(invokeResult.getLogResult()), Charset.forName("UTF-8")));
    }

    if(StringUtils.isNotEmpty(invokeResult.getFunctionError())){
        throw new LambdaInvokeException("Function returned error of type: " + invokeResult.getFunctionError());
    }

    return payload;
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:39,代码来源:LambdaInvokeService.java


示例8: testPerform

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testPerform() throws IOException, ExecutionException, InterruptedException {
    List<JsonParameterVariables> jsonParameterVariables = new ArrayList<>();
    jsonParameterVariables.add(new JsonParameterVariables("KEY", "$.key2"));
    LambdaInvokeVariables clone = new LambdaInvokeVariables(false, "accessKeyId", Secret.fromString("secretKey"), "eu-west-1", "function", "payload", true, true, jsonParameterVariables);
    LambdaInvokeVariables spy = Mockito.spy(clone);

    when(original.getClone()).thenReturn(spy);
    when(spy.getLambdaClientConfig()).thenReturn(clientConfig);
    when(clientConfig.getClient()).thenReturn(lambdaClient);
    final String logBase64 = "bGFtYmRh";
    final String responsePayload = "{\"key2\": \"value2\"}";

    InvokeResult invokeResult = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload.getBytes()));

    when(lambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult);

    FreeStyleProject p = j.createFreeStyleProject();
    p.getPublishersList().add(new LambdaInvokePublisher(Arrays.asList(original, original)));
    FreeStyleBuild build = p.scheduleBuild2(0).get();
    EnvVars environment = build.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));

    assertEquals("value2", environment.get("KEY"));
    assertEquals(Result.SUCCESS, build.getResult());
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:29,代码来源:LambdaInvokePublisherTest.java


示例9: testPerformInstanceRole

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testPerformInstanceRole() throws IOException, ExecutionException, InterruptedException {
    List<JsonParameterVariables> jsonParameterVariables = new ArrayList<>();
    jsonParameterVariables.add(new JsonParameterVariables("KEY", "$.key2"));
    LambdaInvokeVariables clone = new LambdaInvokeVariables(true, "accessKeyId", Secret.fromString("secretKey"), "eu-west-1", "function", "payload", true, true, jsonParameterVariables);
    LambdaInvokeVariables spy = Mockito.spy(clone);

    when(original.getClone()).thenReturn(spy);
    when(spy.getLambdaClientConfig()).thenReturn(clientConfig);
    when(clientConfig.getClient()).thenReturn(lambdaClient);
    final String logBase64 = "bGFtYmRh";
    final String responsePayload = "{\"key2\": \"value2\"}";

    InvokeResult invokeResult = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload.getBytes()));

    when(lambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult);

    FreeStyleProject p = j.createFreeStyleProject();
    p.getPublishersList().add(new LambdaInvokePublisher(Arrays.asList(original, original)));
    FreeStyleBuild build = p.scheduleBuild2(0).get();
    EnvVars environment = build.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));

    assertEquals("value2", environment.get("KEY"));
    assertEquals(Result.SUCCESS, build.getResult());
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:29,代码来源:LambdaInvokePublisherTest.java


示例10: testPerform

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testPerform() throws IOException, ExecutionException, InterruptedException {
    List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>();
    jsonParameterVariables.add(new JsonParameterVariables("KEY", "$.key2"));
    LambdaInvokeBuildStepVariables clone = new LambdaInvokeBuildStepVariables(false, "accessKeyId", Secret.fromString("secretKey"), "eu-west-1", "function", "payload", true, jsonParameterVariables);
    LambdaInvokeBuildStepVariables spy = Mockito.spy(clone);

    when(original.getClone()).thenReturn(spy);
    when(spy.getLambdaClientConfig()).thenReturn(clientConfig);
    when(clientConfig.getClient()).thenReturn(lambdaClient);
    final String logBase64 = "bGFtYmRh";
    final String responsePayload = "{\"key2\": \"value2\"}";

    InvokeResult invokeResult = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload.getBytes()));

    when(lambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult);

    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new LambdaInvokeBuildStep(original));
    FreeStyleBuild build = p.scheduleBuild2(0).get();
    EnvVars environment = build.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));

    assertEquals("value2", environment.get("KEY"));
    assertEquals(Result.SUCCESS, build.getResult());
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:29,代码来源:LambdaInvokeBuildStepTest.java


示例11: testPerformFailure

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testPerformFailure() throws IOException, ExecutionException, InterruptedException {
    List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>();
    jsonParameterVariables.add(new JsonParameterVariables("KEY", "$.key2"));
    LambdaInvokeBuildStepVariables clone = new LambdaInvokeBuildStepVariables(false, "accessKeyId", Secret.fromString("secretKey"), "eu-west-1", "function", "payload", true, jsonParameterVariables);
    LambdaInvokeBuildStepVariables spy = Mockito.spy(clone);

    when(original.getClone()).thenReturn(spy);
    when(spy.getLambdaClientConfig()).thenReturn(clientConfig);
    when(clientConfig.getClient()).thenReturn(lambdaClient);
    final String logBase64 = "bGFtYmRh";
    final String responsePayload = "{\"errorMessage\":\"event_fail\"}";

    InvokeResult invokeResult = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload.getBytes()))
            .withFunctionError("Unhandled");

    when(lambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult);

    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new LambdaInvokeBuildStep(original));
    FreeStyleBuild build = p.scheduleBuild2(0).get();
    EnvVars environment = build.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));

    assertEquals(null, environment.get("KEY"));
    assertEquals(Result.FAILURE, build.getResult());
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:30,代码来源:LambdaInvokeBuildStepTest.java


示例12: testInvokeLambdaFunctionSynchronous

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testInvokeLambdaFunctionSynchronous() throws Exception {
    final String logBase64 = "bGFtYmRh";
    final String log = "lambda";
    final String requestPayload = "{\"key1\": \"value1\"}";
    final String responsePayload = "{\"key2\": \"value2\"}";

    InvokeConfig invokeConfig = new InvokeConfig("function", requestPayload, true, null);

    InvokeResult invokeResult = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload.getBytes()));

    when(awsLambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult);

    String result = lambdaInvokeService.invokeLambdaFunction(invokeConfig);

    verify(awsLambdaClient, times(1)).invoke(invokeRequestArg.capture());
    InvokeRequest invokeRequest = invokeRequestArg.getValue();
    assertEquals("function", invokeRequest.getFunctionName());
    assertEquals(LogType.Tail.toString(), invokeRequest.getLogType());
    assertEquals(requestPayload, new String(invokeRequest.getPayload().array(), Charset.forName("UTF-8")));
    assertEquals(InvocationType.RequestResponse.toString(), invokeRequest.getInvocationType());

    ArgumentCaptor<String> stringArgs = ArgumentCaptor.forClass(String.class);
    verify(jenkinsLogger).log(eq("Lambda invoke request:%n%s%nPayload:%n%s%n"), stringArgs.capture());
    List<String> stringArgValues = stringArgs.getAllValues();
    assertEquals(Arrays.asList(invokeRequest.toString(), requestPayload), stringArgValues);

    verify(jenkinsLogger).log(eq("Log:%n%s%n"), eq(log));

    stringArgs = ArgumentCaptor.forClass(String.class);
    verify(jenkinsLogger).log(eq("Lambda invoke response:%n%s%nPayload:%n%s%n"), stringArgs.capture());
    stringArgValues = stringArgs.getAllValues();
    assertEquals(Arrays.asList(invokeResult.toString(), responsePayload), stringArgValues);

    assertEquals(responsePayload, result);
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:40,代码来源:LambdaInvokeServiceTest.java


示例13: testPerformFailure

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testPerformFailure() throws IOException, ExecutionException, InterruptedException {
    List<JsonParameterVariables> jsonParameterVariables = new ArrayList<>();
    jsonParameterVariables.add(new JsonParameterVariables("KEY", "$.key2"));
    LambdaInvokeVariables clone = new LambdaInvokeVariables(false, "accessKeyId", Secret.fromString("secretKey"), "eu-west-1", "function", "payload", true, true, jsonParameterVariables);
    LambdaInvokeVariables spy = Mockito.spy(clone);

    when(original.getClone()).thenReturn(spy);
    when(spy.getLambdaClientConfig()).thenReturn(clientConfig);
    when(clientConfig.getClient()).thenReturn(lambdaClient);
    final String logBase64 = "bGFtYmRh";
    final String responsePayload = "{\"key2\": \"value2\"}";

    InvokeResult invokeResult = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload.getBytes()));

    when(lambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult);


    LambdaInvokeVariables spy2 = Mockito.spy(clone);
    when(original2.getClone()).thenReturn(spy2);
    when(spy2.getLambdaClientConfig()).thenReturn(clientConfig2);
    when(clientConfig2.getClient()).thenReturn(lambdaClient2);
    final String responsePayload2 = "{\"errorMessage\":\"event_fail\"}";

    InvokeResult invokeResult2 = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload2.getBytes()))
            .withFunctionError("Unhandled");

    when(lambdaClient2.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult2);


    FreeStyleProject p = j.createFreeStyleProject();
    p.getPublishersList().add(new LambdaInvokePublisher(Arrays.asList(original, original2)));
    FreeStyleBuild build = p.scheduleBuild2(0).get();
    EnvVars environment = build.getEnvironment(new LogTaskListener(LOGGER, Level.INFO));

    assertEquals("value2", environment.get("KEY"));
    assertEquals(Result.FAILURE, build.getResult());
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:45,代码来源:LambdaInvokePublisherTest.java


示例14: testInvokeLambdaFunctionSynchronousError

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
@Test
public void testInvokeLambdaFunctionSynchronousError() throws Exception {
    final String logBase64 = "bGFtYmRh";
    final String log = "lambda";
    final String requestPayload = "{\"key1\": \"value1\"}";
    final String responsePayload = "{\"errorMessage\":\"event_fail\"}";

    InvokeConfig invokeConfig = new InvokeConfig("function", requestPayload, true, null);

    InvokeResult invokeResult = new InvokeResult()
            .withLogResult(logBase64)
            .withPayload(ByteBuffer.wrap(responsePayload.getBytes()))
            .withFunctionError("Unhandled");

    when(awsLambdaClient.invoke(any(InvokeRequest.class)))
            .thenReturn(invokeResult);

    try {
        lambdaInvokeService.invokeLambdaFunction(invokeConfig);
        fail("Should fail with LambdaInvokeException");
    } catch (LambdaInvokeException lie){
        assertEquals("Function returned error of type: Unhandled", lie.getMessage());
    }

    verify(awsLambdaClient, times(1)).invoke(invokeRequestArg.capture());
    InvokeRequest invokeRequest = invokeRequestArg.getValue();
    assertEquals("function", invokeRequest.getFunctionName());
    assertEquals(LogType.Tail.toString(), invokeRequest.getLogType());
    assertEquals(requestPayload, new String(invokeRequest.getPayload().array(), Charset.forName("UTF-8")));
    assertEquals(InvocationType.RequestResponse.toString(), invokeRequest.getInvocationType());

    ArgumentCaptor<String> stringArgs = ArgumentCaptor.forClass(String.class);
    verify(jenkinsLogger).log(eq("Lambda invoke request:%n%s%nPayload:%n%s%n"), stringArgs.capture());
    List<String> stringArgValues = stringArgs.getAllValues();
    assertEquals(Arrays.asList(invokeRequest.toString(), requestPayload), stringArgValues);

    verify(jenkinsLogger).log(eq("Log:%n%s%n"), eq(log));

    stringArgs = ArgumentCaptor.forClass(String.class);
    verify(jenkinsLogger).log(eq("Lambda invoke response:%n%s%nPayload:%n%s%n"), stringArgs.capture());
    stringArgValues = stringArgs.getAllValues();
    assertEquals(Arrays.asList(invokeResult.toString(), responsePayload), stringArgValues);
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:44,代码来源:LambdaInvokeServiceTest.java


示例15: execute

import com.amazonaws.services.lambda.model.InvokeResult; //导入依赖的package包/类
/**
 * Executes a lambda function and returns the result of the execution.
 */
@Override
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {

	AmazonKey amazonKey = getAmazonKey( _session, argStruct );

	// Arguments to extract
	String payload = getNamedStringParam( argStruct, "payload", null );
	String functionName = getNamedStringParam( argStruct, "function", null );
	String qualifier = getNamedStringParam( argStruct, "qualifier", null );

	try {

		// Construct the Lambda Client
		InvokeRequest invokeRequest = new InvokeRequest();
		invokeRequest.setInvocationType( InvocationType.RequestResponse );
		invokeRequest.setLogType( LogType.Tail );
		invokeRequest.setFunctionName( functionName );
		invokeRequest.setPayload( payload );
		if ( qualifier != null ) {
			invokeRequest.setQualifier( qualifier );
		}

		// Lambda client must be created with credentials
		BasicAWSCredentials awsCreds = new BasicAWSCredentials( amazonKey.getKey(), amazonKey.getSecret() );
		AWSLambda awsLambda = AWSLambdaClientBuilder.standard()
				.withRegion( amazonKey.getAmazonRegion().toAWSRegion().getName() )
				.withCredentials( new AWSStaticCredentialsProvider( awsCreds ) ).build();

		// Execute and process the results
		InvokeResult result = awsLambda.invoke( invokeRequest );

		// Convert the returned result
		ByteBuffer resultPayload = result.getPayload();
		String resultJson = new String( resultPayload.array(), "UTF-8" );
		Map<String, Object> resultMap = Jackson.fromJsonString( resultJson, Map.class );

		return tagUtils.convertToCfData( resultMap );

	} catch ( Exception e ) {
		throwException( _session, "AmazonLambdaExecute: " + e.getMessage() );
		return cfBooleanData.FALSE;
	}

}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:48,代码来源:LambdaExecute.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CDOSession类代码示例发布时间:2022-05-22
下一篇:
Java ColumnUpdate类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap