@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("toString")) { return this.toString(); } else if (method.getName().equals("hashCode")) { return this.hashCode(); } LambdaFunction annotation = validateInterfaceMethod(method, args); InvokeRequest invokeRequest = buildInvokeRequest(method, annotation, args == null ? null : args[0]); InvokeResult invokeResult = awsLambda.invoke(invokeRequest); return processInvokeResult(method, invokeResult); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { validateInterfaceMethod(method, args); // With Android version before Lollipop (API level 22), args can be an // empty array when the method takes no arguments. final Object buildArg = (args == null || args.length == 0) ? null : args[0]; final InvokeRequest invokeRequest = buildInvokeRequest(method, buildArg); final InvokeResult invokeResult = lambda.invoke(invokeRequest); return processInvokeResult(method, invokeResult); }
@Test public void testInvoke() { String input = "Hello world!"; InvokeResult invokeResult = createInvokeResult(200, null, "\"" + input + "\""); Mockito.when(lambda.invoke(Matchers.any(InvokeRequest.class))).thenReturn(invokeResult); String result = invoker.echo(input); assertEquals("echo", input, result); }
@Test public void testInvokeNoArgument() throws Exception { String echoResult = "No argument"; InvokeResult invokeResult = createInvokeResult(200, null, "\"" + echoResult + "\""); Mockito.when(lambda.invoke(Matchers.any(InvokeRequest.class))).thenReturn(invokeResult); String result = invoker.echoNoArgument(); assertEquals("echoNoArgument", echoResult, result); }
@Test(expected = LambdaFunctionException.class) public void testInvokeException() { String input = "Hello world!"; String error = "Panic!"; String payload = "Bulls eye"; InvokeResult invokeResult = createInvokeResult(200, error, payload); Mockito.when(lambda.invoke(Matchers.any(InvokeRequest.class))).thenReturn(invokeResult); try { invoker.echo(input); } catch (LambdaFunctionException lfe) { assertEquals("error message", error, lfe.getMessage()); assertEquals("payload", payload, lfe.getDetails()); throw lfe; } }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (method.getName().equals("toString")) { return this.toString(); } else if (method.getName().equals("hashCode")) { return this.hashCode(); } LambdaFunction annotation = validateInterfaceMethod(method, args); InvokeRequest invokeRequest = buildInvokeRequest(method, annotation, args == null ? null : args[0]); InvokeResult invokeResult = awsLambda.invoke(invokeRequest); return processInvokeResult(method, invokeResult); }
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(); }
private void invokeRule(AWSLambda awsLambdaClient, String lambdaFunctionName, String params) { InvokeRequest invokeRequest = new InvokeRequest().withFunctionName(lambdaFunctionName).withPayload(ByteBuffer.wrap(params.getBytes())); InvokeResult invokeResult = awsLambdaClient.invoke(invokeRequest); if (invokeResult.getStatusCode() == 200) { invokeResult.getPayload(); } else { log.error("Received a non-OK response from AWS: "+invokeResult.getStatusCode()); } }
private boolean invokeRule(AWSLambda awsLambdaClient, Rule ruleDetails, String invocationId, List<Map<String, Object>> additionalRuleParams) { String ruleParams = ruleDetails.getRuleParams(); if(invocationId != null) { Map<String, Object> ruleParamDetails; try { ruleParamDetails = mapper.readValue(ruleDetails.getRuleParams(), new TypeReference<Map<String, Object>>(){}); ruleParamDetails.put("invocationId", invocationId); ruleParamDetails.put("additionalParams", mapper.writeValueAsString(additionalRuleParams)); ruleParams = mapper.writeValueAsString(ruleParamDetails); } catch (Exception exception) { log.error(UNEXPECTED_ERROR_OCCURRED, exception); } } String functionName = config.getRule().getLambda().getFunctionName(); ByteBuffer payload = ByteBuffer.wrap(ruleParams.getBytes()); InvokeRequest invokeRequest = new InvokeRequest().withFunctionName(functionName).withPayload(payload); InvokeResult invokeResult = awsLambdaClient.invoke(invokeRequest); if (invokeResult.getStatusCode() == 200) { return true; } else { return false; } }
final InvokeResult invoke = lambda.invoke(new InvokeRequest().withFunctionName("beanstalker-codecommit-deployer").withPayload(payloadAsString));
@Override protected Object run() throws Exception { TaskListener listener = this.getContext().get(TaskListener.class); AWSLambda client = AWSClientFactory.create(AWSLambdaClientBuilder.standard(), this.getContext()); String functionName = this.step.getFunctionName(); listener.getLogger().format("Invoke Lambda function %s%n", functionName); InvokeRequest request = new InvokeRequest(); request.withFunctionName(functionName); request.withPayload(this.step.getPayloadAsString()); request.withLogType(LogType.Tail); InvokeResult result = client.invoke(request); listener.getLogger().append(this.getLogResult(result)); String functionError = result.getFunctionError(); if (functionError != null) { throw new RuntimeException("Invoke lambda failed! " + this.getPayloadAsString(result)); } if (this.step.isReturnValueAsString()) { return this.getPayloadAsString(result); } else { return JsonUtils.fromString(this.getPayloadAsString(result)); } }
@TaskAction public void invokeFunction() throws FileNotFoundException, IOException { // to enable conventionMappings feature String functionName = getFunctionName(); if (functionName == null) { throw new GradleException("functionName is required"); } AWSLambdaPluginExtension ext = getProject().getExtensions().getByType(AWSLambdaPluginExtension.class); AWSLambda lambda = ext.getClient(); InvokeRequest request = new InvokeRequest() .withFunctionName(functionName) .withInvocationType(getInvocationType()) .withLogType(getLogType()) .withClientContext(getClientContext()) .withQualifier(getQualifier()); setupPayload(request); invokeResult = lambda.invoke(request); getLogger().info("Invoke Lambda function requested: {}", functionName); }