List of usage examples for com.amazonaws.services.lambda AWSLambda createFunction
CreateFunctionResult createFunction(CreateFunctionRequest createFunctionRequest);
Creates a Lambda function.
From source file:com.netflix.spinnaker.clouddriver.lambda.deploy.ops.CreateLambdaAtomicOperation.java
License:Apache License
private CreateFunctionResult createFunction() { FunctionCode code = new FunctionCode().withS3Bucket(description.getProperty("s3bucket").toString()) .withS3Key(description.getProperty("s3key").toString()); Map<String, String> objTag = new HashMap<>(); for (Map<String, String> tags : description.getTags()) { for (Entry<String, String> entry : tags.entrySet()) { objTag.put(entry.getKey(), entry.getValue()); }/*from w w w.j a va 2 s . c o m*/ } AWSLambda client = getLambdaClient(); CreateFunctionRequest request = new CreateFunctionRequest(); request.setFunctionName(description.getFunctionName()); request.setDescription(description.getDescription()); request.setHandler(description.getHandler()); request.setMemorySize(description.getMemory()); request.setPublish(description.getPublish()); request.setRole(description.getRole()); request.setRuntime(description.getRuntime()); request.setTimeout(description.getTimeout()); request.setCode(code); request.setTags(objTag); CreateFunctionResult result = client.createFunction(request); updateTaskStatus("Finished Creation of AWS Lambda Function Operation..."); return result; }
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"); }// ww w .j ava 2 s . com 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 w w.ja va2 s . c om*/ 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:org.xmlsh.aws.gradle.lambda.AWSLambdaCreateFunctionTask.java
License:BSD License
@TaskAction public void createFunction() throws FileNotFoundException, IOException { // to enable conventionMappings feature String functionName = getFunctionName(); if (functionName == null) throw new GradleException("functionName is required"); File zipFile = getZipFile();//w ww . j a v a 2s . c o m 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()) .withCode(functionCode); createFunctionResult = lambda.createFunction(request); getLogger().info("Create Lambda function requested: {}", createFunctionResult.getFunctionArn()); }
From source file:org.xmlsh.aws.gradle.lambda.AWSLambdaMigrateFunctionTask.java
License:BSD License
private void createFunction(AWSLambda lambda) throws IOException { FunctionCode functionCode;/*from www.j av a2 s .c o m*/ 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()) .withCode(functionCode); createFunctionResult = lambda.createFunction(request); getLogger().info("Create Lambda function requested: {}", createFunctionResult.getFunctionArn()); }