Skip to content

Commit

Permalink
Issue#71 -- support Lambda 'Environment'
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg McNutt committed Nov 29, 2016
1 parent 871a827 commit 9746d17
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ task migrateFunction(type: AWSLambdaMigrateFunctionTask, dependsOn: zip) {
role = "arn:aws:iam::${aws.accountId}:role/lambda-poweruser"
zipFile = zip.archivePath
handler = "DecodeBase64.handler"
environment = [
p1: "Value",
p2: "Value2"
]
}
task invokeFunction(type: AWSLambdaInvokeTask) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ configurations {
// ======== library versions ========
ext {
lombokVersion = "1.16.2"
awsJavaSdkVersion = "1.11.27"
awsJavaSdkVersion = "1.11.60"
groovyVersion = "2.3.7"
junitVersion = "4.12"
hamcrestVersion = "1.3"
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Nov 08 12:52:08 JST 2016
#Mon Nov 28 15:27:27 PST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
6 changes: 6 additions & 0 deletions samples/08-lambda/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ task migrateFunction(type: AWSLambdaMigrateFunctionTask, dependsOn: zip) {
role = "arn:aws:iam::${aws.accountId}:role/lambda-poweruser"
zipFile = zip.archivePath
handler = "DecodeBase64.handler"
runtime = "Nodejs43"

environment = [
TARGET: "ascii"
]

// optional publish value
publish = true
Expand All @@ -49,6 +54,7 @@ task migrateFunctionWithVpc(type: AWSLambdaMigrateFunctionTask, dependsOn: zip)
role = "arn:aws:iam::${aws.accountId}:role/lambda-poweruser"
zipFile = zip.archivePath
handler = "DecodeBase64.handler"
runtime = "Nodejs43"

// optional VPC config
vpc = new VpcConfigWrapper()
Expand Down
2 changes: 1 addition & 1 deletion samples/08-lambda/function/DecodeBase64.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ console.log('Loading function');

exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
var payload = new Buffer(event.data, 'base64').toString('ascii');
var payload = new Buffer(event.data, 'base64').toString(process.env.TARGET);
context.succeed(payload);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;
Expand All @@ -32,6 +33,7 @@
import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.model.CreateFunctionRequest;
import com.amazonaws.services.lambda.model.CreateFunctionResult;
import com.amazonaws.services.lambda.model.Environment;
import com.amazonaws.services.lambda.model.FunctionCode;
import com.amazonaws.services.lambda.model.Runtime;
import com.amazonaws.services.lambda.model.VpcConfig;
Expand Down Expand Up @@ -78,6 +80,10 @@ public class AWSLambdaCreateFunctionTask extends ConventionTask {
@Setter
private VpcConfigWrapper vpc;

@Getter
@Setter
private Map<String, String> environment;

@Getter
@Setter
private Boolean publish;
Expand Down Expand Up @@ -136,6 +142,7 @@ public void createFunction() throws FileNotFoundException, IOException {
.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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;
Expand All @@ -32,6 +33,7 @@
import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.model.CreateFunctionRequest;
import com.amazonaws.services.lambda.model.CreateFunctionResult;
import com.amazonaws.services.lambda.model.Environment;
import com.amazonaws.services.lambda.model.FunctionCode;
import com.amazonaws.services.lambda.model.FunctionConfiguration;
import com.amazonaws.services.lambda.model.GetFunctionRequest;
Expand Down Expand Up @@ -86,6 +88,10 @@ public class AWSLambdaMigrateFunctionTask extends ConventionTask {
@Setter
private VpcConfigWrapper vpc;

@Getter
@Setter
private Map<String, String> environment;

@Getter
@Setter
private Boolean publish;
Expand Down Expand Up @@ -167,6 +173,7 @@ private void createFunction(AWSLambda lambda) throws IOException {
.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());
Expand Down Expand Up @@ -241,6 +248,7 @@ private void updateFunctionConfiguration(AWSLambda lambda, FunctionConfiguration
.withDescription(updateDescription)
.withTimeout(updateTimeout)
.withVpcConfig(getVpcConfig())
.withEnvironment(new Environment().withVariables(getEnvironment()))
.withMemorySize(updateMemorySize);

UpdateFunctionConfigurationResult updateFunctionConfiguration = lambda.updateFunctionConfiguration(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

import lombok.Getter;
import lombok.Setter;
Expand All @@ -26,6 +27,7 @@
import org.gradle.api.tasks.TaskAction;

import com.amazonaws.services.lambda.AWSLambda;
import com.amazonaws.services.lambda.model.Environment;
import com.amazonaws.services.lambda.model.UpdateFunctionConfigurationRequest;
import com.amazonaws.services.lambda.model.UpdateFunctionConfigurationResult;

Expand Down Expand Up @@ -55,6 +57,10 @@ public class AWSLambdaUpdateFunctionConfigurationTask extends ConventionTask {
@Setter
private Integer memorySize;

@Getter
@Setter
private Map<String, String> environment;

@Getter
private UpdateFunctionConfigurationResult updateFunctionConfiguration;

Expand Down Expand Up @@ -82,7 +88,8 @@ public void createFunction() throws FileNotFoundException, IOException {
.withHandler(getHandler())
.withDescription(getFunctionDescription())
.withTimeout(getTimeout())
.withMemorySize(getMemorySize());
.withMemorySize(getMemorySize())
.withEnvironment(new Environment().withVariables(getEnvironment()));
updateFunctionConfiguration = lambda.updateFunctionConfiguration(request);
getLogger().info("Update Lambda function configuration requested: {}",
updateFunctionConfiguration.getFunctionArn());
Expand Down

0 comments on commit 9746d17

Please sign in to comment.