List of usage examples for com.amazonaws.services.lambda.model Environment Environment
Environment
From source file:jp.classmethod.aws.gradle.lambda.AWSLambdaCreateFunctionTask.java
License:Apache License
@TaskAction public void createFunction() throws FileNotFoundException, IOException { // to enable conventionMappings feature String functionName = getFunctionName(); if (functionName == null) { throw new GradleException("functionName is required"); }//from w ww . ja va 2 s . c o m File zipFile = getZipFile(); S3File s3File = getS3File(); if ((zipFile == null && s3File == null) || (zipFile != null && s3File != null)) { throw new GradleException("exactly one of zipFile or s3File is required"); } AWSLambdaPluginExtension ext = getProject().getExtensions().getByType(AWSLambdaPluginExtension.class); AWSLambda lambda = ext.getClient(); FunctionCode functionCode; if (zipFile != null) { try (RandomAccessFile raf = new RandomAccessFile(getZipFile(), "r"); FileChannel channel = raf.getChannel()) { MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); buffer.load(); functionCode = new FunctionCode().withZipFile(buffer); } } else { // assume s3File is not null s3File.validate(); functionCode = new FunctionCode().withS3Bucket(s3File.getBucketName()).withS3Key(s3File.getKey()) .withS3ObjectVersion(s3File.getObjectVersion()); } CreateFunctionRequest request = new CreateFunctionRequest().withFunctionName(getFunctionName()) .withRuntime(getRuntime()).withRole(getRole()).withHandler(getHandler()) .withDescription(getFunctionDescription()).withTimeout(getTimeout()).withMemorySize(getMemorySize()) .withPublish(getPublish()).withVpcConfig(getVpcConfig()) .withEnvironment(new Environment().withVariables(getEnvironment())).withCode(functionCode); createFunctionResult = lambda.createFunction(request); getLogger().info("Create Lambda function requested: {}", createFunctionResult.getFunctionArn()); }
From source file:jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask.java
License:Apache License
private void createFunction(AWSLambda lambda) throws IOException { // to enable conventionMappings feature File zipFile = getZipFile();/*from w ww .ja v a2s. co m*/ S3File s3File = getS3File(); FunctionCode functionCode; if (zipFile != null) { try (RandomAccessFile raf = new RandomAccessFile(getZipFile(), "r"); FileChannel channel = raf.getChannel()) { MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); buffer.load(); functionCode = new FunctionCode().withZipFile(buffer); } } else { // assume s3File is not null functionCode = new FunctionCode().withS3Bucket(s3File.getBucketName()).withS3Key(s3File.getKey()) .withS3ObjectVersion(s3File.getObjectVersion()); } CreateFunctionRequest request = new CreateFunctionRequest().withFunctionName(getFunctionName()) .withRuntime(getRuntime()).withRole(getRole()).withHandler(getHandler()) .withDescription(getFunctionDescription()).withTimeout(getTimeout()).withMemorySize(getMemorySize()) .withPublish(getPublish()).withVpcConfig(getVpcConfig()) .withEnvironment(new Environment().withVariables(getEnvironment())).withCode(functionCode); createFunctionResult = lambda.createFunction(request); getLogger().info("Create Lambda function requested: {}", createFunctionResult.getFunctionArn()); }
From source file:jp.classmethod.aws.gradle.lambda.AWSLambdaMigrateFunctionTask.java
License:Apache License
private void updateFunctionConfiguration(AWSLambda lambda, FunctionConfiguration config) { String updateFunctionName = getFunctionName(); if (updateFunctionName == null) { updateFunctionName = config.getFunctionName(); }/*from w ww .j a v a 2 s. co m*/ String updateRole = getRole(); if (updateRole == null) { updateRole = config.getRole(); } Runtime updateRuntime = getRuntime(); if (updateRuntime == null) { updateRuntime = Runtime.fromValue(config.getRuntime()); } String updateHandler = getHandler(); if (updateHandler == null) { updateHandler = config.getHandler(); } String updateDescription = getFunctionDescription(); if (updateDescription == null) { updateDescription = config.getDescription(); } Integer updateTimeout = getTimeout(); if (updateTimeout == null) { updateTimeout = config.getTimeout(); } Integer updateMemorySize = getMemorySize(); if (updateMemorySize == null) { updateMemorySize = config.getMemorySize(); } UpdateFunctionConfigurationRequest request = new UpdateFunctionConfigurationRequest() .withFunctionName(updateFunctionName).withRole(updateRole).withRuntime(updateRuntime) .withHandler(updateHandler).withDescription(updateDescription).withTimeout(updateTimeout) .withVpcConfig(getVpcConfig()).withEnvironment(new Environment().withVariables(getEnvironment())) .withMemorySize(updateMemorySize); UpdateFunctionConfigurationResult updateFunctionConfiguration = lambda.updateFunctionConfiguration(request); getLogger().info("Update Lambda function configuration requested: {}", updateFunctionConfiguration.getFunctionArn()); }
From source file:jp.classmethod.aws.gradle.lambda.AWSLambdaUpdateFunctionConfigurationTask.java
License:Apache License
@TaskAction public void createFunction() throws FileNotFoundException, IOException { // to enable conventionMappings feature String functionName = getFunctionName(); if (functionName == null) { throw new GradleException("functionName is required"); }/* w w w . ja v a 2 s . c om*/ AWSLambdaPluginExtension ext = getProject().getExtensions().getByType(AWSLambdaPluginExtension.class); AWSLambda lambda = ext.getClient(); UpdateFunctionConfigurationRequest request = new UpdateFunctionConfigurationRequest() .withFunctionName(getFunctionName()).withRole(getRole()).withHandler(getHandler()) .withDescription(getFunctionDescription()).withTimeout(getTimeout()).withMemorySize(getMemorySize()) .withEnvironment(new Environment().withVariables(getEnvironment())); updateFunctionConfiguration = lambda.updateFunctionConfiguration(request); getLogger().info("Update Lambda function configuration requested: {}", updateFunctionConfiguration.getFunctionArn()); }