private CreateFunctionResult createFunction() { final String executionRole = initExecutionRole(); final FunctionCode fcod = loadCode(); final CreateFunctionRequest cfrq = new CreateFunctionRequest().withCode(fcod) .withDescription("Translator Slack event handler") .withFunctionName(FunctionName) .withHandler(HandlerSpec) .withMemorySize(256) .withPublish(true) .withRole(executionRole) .withRuntime(Runtime.Java8); return this.awsLambdaClient.createFunction(cfrq); }
private CreateFunctionResult createFunction() { final String executionRole = initExecutionRole(); final FunctionCode fcod = loadCode(); final CreateFunctionRequest cfrq = new CreateFunctionRequest().withCode(fcod) .withDescription("Translator Slack event handler") .withFunctionName(FunctionName) .withHandler("com.banjocreek.translatebot.EventHandler::handle") .withMemorySize(1024) .withTimeout(30) .withPublish(true) .withRole(executionRole) .withRuntime(Runtime.Java8); return this.awsLambdaClient.createFunction(cfrq); }
private CreateFunctionResult createFunction() { final String executionRole = initExecutionRole(); final FunctionCode fcod = loadCode(); final CreateFunctionRequest cfrq = new CreateFunctionRequest().withCode(fcod) .withDescription("Translator Slack event handler") .withFunctionName(FunctionName) .withHandler(EntryPoint) .withMemorySize(1024) .withTimeout(30) .withPublish(true) .withRole(executionRole) .withRuntime(Runtime.Java8); return this.awsLambdaClient.createFunction(cfrq); }
private String createLambda(AWSLambdaClient lambdaClient, String handler, String name, String description) { CreateFunctionRequest request = new CreateFunctionRequest(); request.setCode(buildFunctionCode()); request.setDescription(description); request.setFunctionName(name); request.setHandler(handler); request.setMemorySize(memory); request.setPublish(true); // assume or create a role? request.setRole(lambdaRoleARN); request.setRuntime("java8"); request.setTimeout(handlerTimeout); CreateFunctionResult result = lambdaClient.createFunction(request); return result.getFunctionArn(); }
@Before public void setUp() throws Exception { description = "description"; functionName = "function"; handler = "function.handler"; memory = 1024; role = "role"; runtime = "nodejs"; publish = Boolean.FALSE; functionVersion = null; createAlias = Boolean.FALSE; alias = null; timeout = 30; subnets = new ArrayList<>(); securityGroups = new ArrayList<>(); kmsArn = "arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012"; environment = new HashMap<>(); environment.put("key", "value"); deadLetterQueueArn = "arn:aws:sqs:us-east-1:123456789012:queueName"; lambdaDeployService = new LambdaDeployService(awsLambdaClient, jenkinsLogger); when(awsLambdaClient.updateFunctionConfiguration(any(UpdateFunctionConfigurationRequest.class))) .thenReturn(new UpdateFunctionConfigurationResult()); when(awsLambdaClient.updateFunctionCode(any(UpdateFunctionCodeRequest.class))) .thenReturn(new UpdateFunctionCodeResult()); when(awsLambdaClient.createFunction(any(CreateFunctionRequest.class))) .thenReturn(new CreateFunctionResult()); }
private void calledCreateFunction(Boolean called) { if (called) { ArgumentCaptor<CreateFunctionRequest> args = ArgumentCaptor.forClass(CreateFunctionRequest.class); verify(awsLambdaClient, times(1)).createFunction(args.capture()); try { CreateFunctionRequest expected = new CreateFunctionRequest() .withDescription(description) .withFunctionName(functionName) .withHandler(handler) .withMemorySize(memory) .withRole(role) .withTimeout(timeout) .withPublish(publish) .withRuntime(runtime) .withVpcConfig(new VpcConfig().withSubnetIds(subnets).withSecurityGroupIds(securityGroups)) .withCode(new FunctionCode().withZipFile(ByteBuffer.wrap(FileUtils.readFileToByteArray(getZipFile())))) .withKMSKeyArn(kmsArn) .withEnvironment(new Environment().withVariables(environment)) .withDeadLetterConfig(new DeadLetterConfig().withTargetArn(deadLetterQueueArn)); assertEquals(expected, args.getValue()); } catch (IOException e) { fail("Couldn't process echo.zip"); } } else { verify(awsLambdaClient, never()).createFunction(any(CreateFunctionRequest.class)); } }
private void setPublishVersion(String version){ this.functionVersion = version; this.publish = true; CreateFunctionResult createFunctionResult = new CreateFunctionResult() .withVersion(version); when(awsLambdaClient.createFunction(any(CreateFunctionRequest.class))) .thenReturn(createFunctionResult); UpdateFunctionCodeResult updateFunctionCodeResult = new UpdateFunctionCodeResult() .withVersion(version); when(awsLambdaClient.updateFunctionCode(any(UpdateFunctionCodeRequest.class))) .thenReturn(updateFunctionCodeResult); }