Java 类com.amazonaws.services.lambda.model.FunctionCode 实例源码

项目:java-translatebot    文件:OauthHandlerDeployer.java   
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);

    }
项目:java-translatebot    文件:EventHandlerDeployer.java   
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);

    }
项目:java-translatebot    文件:CommandHandlerDeployer.java   
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);

    }
项目:aws-lambda-jenkins-plugin    文件:LambdaUploaderTest.java   
@Test
public void testUploadSuccess() throws Exception {
    DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full", false, null, false, new ArrayList<String>(), new ArrayList<String>());
    File file = new File("path");

    when(zipper.getZip(any(String.class))).thenReturn(file);
    when(service.deployLambda(any(DeployConfig.class), any(FunctionCode.class), any(UpdateModeValue.class)))
            .thenReturn(true);

    LambdaUploader uploader = new LambdaUploader(service, zipper, logger);
    Boolean uploaded = uploader.upload(deployConfig);

    verify(logger, times(1)).log("%nStarting lambda deployment procedure");
    verify(service, times(1)).deployLambda(eq(deployConfig), any(FunctionCode.class), eq(UpdateModeValue.Full));
    assertTrue(uploaded);
}
项目:aws-lambda-jenkins-plugin    文件:LambdaUploaderTest.java   
@Test
public void testUploadFailure() throws Exception {
    DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full", false, null, false, new ArrayList<String>(), new ArrayList<String>());
    File file = new File("path");

    when(zipper.getZip(any(String.class))).thenReturn(file);
    when(service.deployLambda(any(DeployConfig.class), any(FunctionCode.class), any(UpdateModeValue.class)))
            .thenReturn(false);

    LambdaUploader uploader = new LambdaUploader(service, zipper, logger);
    Boolean uploaded = uploader.upload(deployConfig);

    verify(logger, times(1)).log("%nStarting lambda deployment procedure");
    verify(service, times(1)).deployLambda(eq(deployConfig), any(FunctionCode.class), eq(UpdateModeValue.Full));
    assertFalse(uploaded);
}
项目:aws-lambda-deploy    文件:AWSLambdaDeployer.java   
private FunctionCode buildFunctionCode() {
    FunctionCode functionCode = new FunctionCode();
    functionCode.setS3Bucket(codeS3Bucket);
    functionCode.setS3Key(artifactName);
    functionCode.setS3ObjectVersion(codeS3Version);

    return functionCode;
}
项目:aws-lambda-jenkins-plugin    文件:LambdaUploaderTest.java   
@Test
public void testUploadNoArtifact() throws Exception {
    DeployConfig deployConfig = new DeployConfig("location", "description", "function", "handler", 1024, "role", "runtime", 30, "full", false, null, false, new ArrayList<String>(), new ArrayList<String>());

    when(zipper.getZip(any(String.class))).thenReturn(null);
    when(service.deployLambda(any(DeployConfig.class), any(FunctionCode.class), any(UpdateModeValue.class)))
            .thenReturn(true);

    LambdaUploader uploader = new LambdaUploader(service, zipper, logger);
    Boolean uploaded = uploader.upload(deployConfig);

    verify(logger, times(1)).log("%nStarting lambda deployment procedure");
    verify(service, times(1)).deployLambda(eq(deployConfig), any(FunctionCode.class), eq(UpdateModeValue.Full));
    assertTrue(uploaded);
}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
@Test
public void getFunctionCodeFile() throws IOException, InterruptedException {
    File file = testUtil.getResource("echo.zip");
    ByteBuffer beforedeleteByteBuffer = getFunctionZip(file);

    when(workSpaceZipper.getZip(any(String.class))).thenReturn(file);

    FunctionCode functionCode = lambdaDeployService.getFunctionCode("location.zip", workSpaceZipper);

    assertEquals(beforedeleteByteBuffer, functionCode.getZipFile());
    assertNull(functionCode.getS3Bucket());
    assertNull(functionCode.getS3Key());
    assertNull(functionCode.getS3ObjectVersion());

}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
@Test
public void getFunctionCodeS3() throws IOException, InterruptedException {

    FunctionCode functionCode = lambdaDeployService.getFunctionCode("s3://bucket/key/subkey1.zip", workSpaceZipper);

    verify(workSpaceZipper, times(0)).getZip(any(String.class));
    assertEquals("bucket", functionCode.getS3Bucket());
    assertEquals("key/subkey1.zip", functionCode.getS3Key());
    assertNull(functionCode.getS3ObjectVersion());
    assertNull(functionCode.getZipFile());
}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
@Test
public void getFunctionCodeS3ShortKey() throws IOException, InterruptedException {

    FunctionCode functionCode = lambdaDeployService.getFunctionCode("s3://bucket/a", workSpaceZipper);

    verify(workSpaceZipper, times(0)).getZip(any(String.class));
    assertEquals("bucket", functionCode.getS3Bucket());
    assertEquals("a", functionCode.getS3Key());
    assertNull(functionCode.getS3ObjectVersion());
    assertNull(functionCode.getZipFile());
}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
@Test
public void getFunctionCodeS3NoKeyWithSlash() throws IOException, InterruptedException {

    FunctionCode functionCode = lambdaDeployService.getFunctionCode("s3://bucket/", workSpaceZipper);

    verify(workSpaceZipper, times(0)).getZip(any(String.class));
    assertEquals("bucket", functionCode.getS3Bucket());
    assertNull(functionCode.getS3Key());
    assertNull(functionCode.getS3ObjectVersion());
    assertNull(functionCode.getZipFile());
}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
@Test
public void getFunctionCodeS3NoKeyWithoutSlash() throws IOException, InterruptedException {

    FunctionCode functionCode = lambdaDeployService.getFunctionCode("s3://bucket", workSpaceZipper);

    verify(workSpaceZipper, times(0)).getZip(any(String.class));
    assertNull(functionCode.getS3Bucket());
    assertNull(functionCode.getS3Key());
    assertNull(functionCode.getS3ObjectVersion());
    assertNull(functionCode.getZipFile());
}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
@Test
public void getFunctionCodeS3Version() throws IOException, InterruptedException {

    FunctionCode functionCode = lambdaDeployService.getFunctionCode("s3://bucket/key/subkey1.zip?versionId=abc/def|123", workSpaceZipper);

    verify(workSpaceZipper, times(0)).getZip(any(String.class));
    assertEquals("bucket", functionCode.getS3Bucket());
    assertEquals("key/subkey1.zip", functionCode.getS3Key());
    assertEquals("abc/def|123", functionCode.getS3ObjectVersion());
    assertNull(functionCode.getZipFile());
}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
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));
    }
}
项目:aws-lambda-jenkins-plugin    文件:LambdaDeployServiceTest.java   
private FunctionCode getFunctionCode() throws IOException {
    ClassLoader classLoader = getClass().getClassLoader();
    URL resource = classLoader.getResource("echo.zip");
    if(resource != null){
        File zipFile = new File(resource.getFile());
        return new FunctionCode()
                .withZipFile(getFunctionZip(zipFile));
    } else {
        throw new IllegalStateException("Could not load echo.zip");
    }
}
项目:aws-lambda-jenkins-plugin    文件:LambdaUploader.java   
public Boolean upload(DeployConfig config) throws IOException, InterruptedException {
    logger.log("%nStarting lambda deployment procedure");

    FunctionCode functionCode = lambda.getFunctionCode(config.getArtifactLocation(), zipper);
    return lambda.deployLambda(config, functionCode, UpdateModeValue.fromString(config.getUpdateMode()));
}
项目:java-translatebot    文件:OauthHandlerDeployer.java   
private FunctionCode loadCode() {

        return new FunctionCode().withZipFile(loadJar());
    }
项目:java-translatebot    文件:EventHandlerDeployer.java   
private FunctionCode loadCode() {

        return new FunctionCode().withZipFile(loadJar());
    }
项目:java-translatebot    文件:CommandHandlerDeployer.java   
private FunctionCode loadCode() {

        return new FunctionCode().withZipFile(loadJar());
    }