Skip to content

Commit

Permalink
Merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanRoy committed Nov 30, 2021
2 parents ad46b9a + 7b8184b commit e635116
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### Usage
`group id: com.github.seanroy`<br />
`artifact id: lambda-maven-plugin`<br />
`version: 2.3.3`<br />
`version: 2.3.4`<br />
<br/><br/>
Please note that the artifact has been renamed from lambduh-maven-plugin to
lambda-maven-plugin.
Expand Down Expand Up @@ -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 [[email protected]](mailto:[email protected])

2.3.3
* Added Support for SQS Trigger

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>com.github.seanroy</groupId>
<artifactId>lambda-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>2.3.3</version>
<version>2.3.4</version>

<name>lambda-maven-plugin Maven Mojo</name>
<description>A maven plugin that deploys functions to AWS Lambda</description>
Expand Down Expand Up @@ -48,7 +48,7 @@
</contributors>

<properties>
<aws.version>1.11.271</aws.version>
<aws.version>1.12.68</aws.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -148,12 +148,12 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-encryption-sdk-java</artifactId>
<version>1.3.1</version>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -169,7 +169,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/github/seanroy/plugins/AbstractLambdaMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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 <State: %s, LastUpdateStatus: %s>, 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());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/github/seanroy/utils/AWSEncryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, KmsMasterKey> decryptResult = crypto.decryptString(prov, cipherText);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/seanroy/utils/JsonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public static String toJson(Object message) throws JsonProcessingException {
}

public static <T> T fromJson(String body) throws IOException {
return mapper.readValue(body, new TypeReference<List<LambdaFunction>>(){});
return (T) mapper.readValue(body, new TypeReference<List<LambdaFunction>>(){});
}
}

0 comments on commit e635116

Please sign in to comment.