diff --git a/NOTICE b/NOTICE index b8a6c84..83d341e 100644 --- a/NOTICE +++ b/NOTICE @@ -1,5 +1,5 @@ Lambda Maven plugin - Copyright 2018 Sean N. Roy + Copyright 2021 Sean N. Roy Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index 0f651aa..c5320bd 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### Usage `group id: com.github.seanroy`
`artifact id: lambda-maven-plugin`
-`version: 2.3.3`
+`version: 2.3.4`


Please note that the artifact has been renamed from lambduh-maven-plugin to lambda-maven-plugin. @@ -220,6 +220,10 @@ to the file. If you add more pom's as part of enhancing the test suite, please remember to add them to .gitignore. ### Releases +2.3.4 +* Resolves [Issue 117](https://github.com/SeanRoy/lambda-maven-plugin/issues/117) https://github.com/juger89 +* Thanks [juger89@gmail.com](mailto:juger89@gmail.com) + 2.3.3 * Added Support for SQS Trigger diff --git a/pom.xml b/pom.xml index 2842c7d..d5b4252 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.github.seanroy lambda-maven-plugin maven-plugin - 2.3.3 + 2.3.4 lambda-maven-plugin Maven Mojo A maven plugin that deploys functions to AWS Lambda @@ -48,7 +48,7 @@ - 1.11.271 + 1.12.68 UTF-8 @@ -148,12 +148,12 @@ com.amazonaws aws-encryption-sdk-java - 1.3.1 + 2.2.0 junit junit - 4.12 + 4.13.1 test @@ -169,7 +169,7 @@ org.apache.httpcomponents httpclient - 4.5.3 + 4.5.13 com.google.code.gson @@ -262,7 +262,7 @@ org.apache.maven.plugins maven-plugin-plugin - 3.4 + 3.6.1 default-descriptor diff --git a/src/main/java/com/github/seanroy/plugins/AbstractLambdaMojo.java b/src/main/java/com/github/seanroy/plugins/AbstractLambdaMojo.java index a9aeb28..e6f86c7 100644 --- a/src/main/java/com/github/seanroy/plugins/AbstractLambdaMojo.java +++ b/src/main/java/com/github/seanroy/plugins/AbstractLambdaMojo.java @@ -17,6 +17,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import com.amazonaws.services.lambda.model.GetFunctionRequest; +import com.amazonaws.services.lambda.model.GetFunctionResult; import com.amazonaws.services.lambda.model.UpdateFunctionCodeRequest; import com.amazonaws.services.lambda.model.UpdateFunctionCodeResult; import com.amazonaws.services.s3.model.*; @@ -293,6 +295,24 @@ void uploadJarToS3() throws Exception { .withS3Key(fileName) .withPublish(lambdaFunction.isPublish()); UpdateFunctionCodeResult updateFunctionCodeResult = lambdaClient.updateFunctionCode(updateFunctionRequest); + + // wait until the UpdateFunctionCode finishes processing to avoid com.amazonaws.services.lambda.model.ResourceConflictException. See: https://docs.aws.amazon.com/lambda/latest/dg/functions-states.html + GetFunctionRequest getFunctionRequest = new GetFunctionRequest() + .withFunctionName(lambdaFunction.getFunctionName()); + GetFunctionResult getFunctionResult = lambdaClient.getFunction(getFunctionRequest); + + while (!getFunctionResult.getConfiguration().getState().equals("Active") + || !getFunctionResult.getConfiguration().getLastUpdateStatus().equals("Successful")) { + try { + getLog().info(String.format("UpdateFunctionCode for %s is still processing , waiting... ", lambdaFunction.getFunctionName(), getFunctionResult.getConfiguration().getState(), getFunctionResult.getConfiguration().getLastUpdateStatus())); + Thread.sleep(3000); + getFunctionResult = lambdaClient.getFunction(getFunctionRequest); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + getLog().info("UpdateFunctionCode finished successfully for " + lambdaFunction.getFunctionName()); + return lambdaFunction .withVersion(updateFunctionCodeResult.getVersion()) .withFunctionArn(updateFunctionCodeResult.getFunctionArn()); diff --git a/src/main/java/com/github/seanroy/utils/AWSEncryption.java b/src/main/java/com/github/seanroy/utils/AWSEncryption.java index 045b79a..cfeb105 100644 --- a/src/main/java/com/github/seanroy/utils/AWSEncryption.java +++ b/src/main/java/com/github/seanroy/utils/AWSEncryption.java @@ -20,20 +20,20 @@ public AWSEncryption(String keyArn) { public String encryptString(String data) { // Instantiate the SDK - final AwsCrypto crypto = new AwsCrypto(); + final AwsCrypto crypto = AwsCrypto.builder().build(); // Set up the KmsMasterKeyProvider backed by the default credentials - final KmsMasterKeyProvider prov = new KmsMasterKeyProvider(keyArn); + final KmsMasterKeyProvider prov = KmsMasterKeyProvider.builder().buildStrict(keyArn); return crypto.encryptString(prov, data).getResult(); } public String decryptString(String cipherText) { // Instantiate the SDK - final AwsCrypto crypto = new AwsCrypto(); + final AwsCrypto crypto = AwsCrypto.builder().build(); // Set up the KmsMasterKeyProvider backed by the default credentials - final KmsMasterKeyProvider prov = new KmsMasterKeyProvider(keyArn); + final KmsMasterKeyProvider prov = KmsMasterKeyProvider.builder().buildStrict(keyArn); // Decrypt the data final CryptoResult decryptResult = crypto.decryptString(prov, cipherText); diff --git a/src/main/java/com/github/seanroy/utils/JsonUtil.java b/src/main/java/com/github/seanroy/utils/JsonUtil.java index 18a672d..907b5ee 100644 --- a/src/main/java/com/github/seanroy/utils/JsonUtil.java +++ b/src/main/java/com/github/seanroy/utils/JsonUtil.java @@ -45,6 +45,6 @@ public static String toJson(Object message) throws JsonProcessingException { } public static T fromJson(String body) throws IOException { - return mapper.readValue(body, new TypeReference>(){}); + return (T) mapper.readValue(body, new TypeReference>(){}); } }