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(); }
private String iarn(final CreateFunctionResult function) { final String rval = this.awsLambdaClient.listFunctions() .getFunctions() .stream() .filter(f -> f.getFunctionName().equals(function.getFunctionName())) .findAny() .map(f -> f.getFunctionArn()) .map(farn -> "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/" + farn + "/invocations") .get(); System.out.println("farn: " + rval); return rval; }
private void permitInvokeLambda(final String accountId, final CreateRestApiResult createApiResult, final CreateFunctionResult function) { final String sourceArn = "arn:aws:execute-api:us-east-1:" + accountId + ":" + createApiResult.getId() + "/*/" + HttpMethod + "/" + Path; System.out.println(sourceArn); // allow api to invoke lambda function final AddPermissionRequest aprq = new AddPermissionRequest().withFunctionName(function.getFunctionName()) .withAction("lambda:InvokeFunction") .withPrincipal("apigateway.amazonaws.com") .withStatementId("sid" + Math.abs(rng.nextLong())) .withSourceArn(sourceArn); this.awsLambdaClient.addPermission(aprq); }
private void permitInvokeLambda(final String accountId, final CreateRestApiResult createApiResult, final CreateFunctionResult function) { final String sourceArn = "arn:aws:execute-api:us-east-1:" + accountId + ":" + createApiResult.getId() + "/*/POST/" + Path; System.out.println(sourceArn); // allow api to invoke lambda function final AddPermissionRequest aprq = new AddPermissionRequest().withFunctionName(function.getFunctionName()) .withAction("lambda:InvokeFunction") .withPrincipal("apigateway.amazonaws.com") .withStatementId("sid" + Math.abs(rng.nextLong())) .withSourceArn(sourceArn); this.awsLambdaClient.addPermission(aprq); }
@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 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); }
private void createApi(final CreateFunctionResult function) { final CreateRestApiResult createApiResult = createApi(); final CreateResourceResult crrs = createResource(createApiResult); final String iarn = iarn(function); createMethod(createApiResult, crrs, iarn); stageApi(createApiResult); final String accountId = accountId(iarn); permitInvokeLambda(accountId, createApiResult, function); }
private void createApi(final CreateFunctionResult function) { final CreateRestApiResult createApiResult = createApi(); final CreateResourceResult crrs = createResource(createApiResult); createPostMethod(createApiResult, crrs); final String iarn = iarn(function); integratePostMethod(createApiResult, crrs, iarn); stageApi(createApiResult); final String accountId = accountId(iarn); permitInvokeLambda(accountId, createApiResult, function); }
public void deploy() { final CreateFunctionResult function = createFunction(); createApi(function); }