Skip to content

Commit

Permalink
Merge branch 'v2' into dependabot/maven/v2/org.assertj-assertj-core-3…
Browse files Browse the repository at this point in the history
….25.3
  • Loading branch information
scottgerring authored Feb 26, 2024
2 parents ff7b479 + e62e2cd commit 3a365cb
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 87 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ updates:
# Ignore Mockito 5.X.X as it does not support Java 8
- dependency-name: "org.mockito:mockito-*"
update-types: ["version-update:semver-major"]

- package-ecosystem: "maven"
directory: "/"
target-branch: "v2"
schedule:
interval: "weekly"
labels:
- "maven"
- "dependencies"
27 changes: 0 additions & 27 deletions .github/workflows/pr_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,6 @@ jobs:
if: ${{ matrix.java != '8' }}
working-directory: examples/powertools-examples-core-utilities/kotlin
run: ./gradlew build
- name: Setup Terraform
if: ${{ matrix.java == '11' }}
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 #v2.0.3
- name: Setup AWS credentials
if: ${{ matrix.java == '11' }}
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }}
aws-region: ${{ env.AWS_REGION }}
- name: Terraform validate
working-directory: examples/powertools-examples-core-utilities/terraform
if: ${{ matrix.java == '11' }}
run: |
terraform -version
terraform init -backend=false
terraform validate
terraform plan
- name: Setup Terraform lint
if: ${{ matrix.java == '11' }}
uses: terraform-linters/setup-tflint@a5a1af8c6551fb10c53f1cd4ba62359f1973746f # v3.1.1
- name: Terraform lint
working-directory: examples/powertools-examples-core-utilities/terraform
if: ${{ matrix.java == '11' }}
run: |
tflint --version
tflint --init
tflint -f compact
- name: Upload coverage to Codecov
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
if: ${{ matrix.java == '11' }} # publish results once
Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/pr_iac_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Validate IaC

on:
push:
branches:
- main
- v2
pull_request:
branches:
- main
- v2
paths:
- 'examples/**'
jobs:
linter:
runs-on: ubuntu-latest
strategy:
matrix:
project: ["sam", "gradle", "kotlin"]
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Setup java JDK
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
distribution: 'corretto'
java-version: 11
- name: Build Project
working-directory: .
run: |
mvn install -DskipTests
- name: Run SAM validator to check syntax of IaC templates - Java
working-directory: examples/powertools-examples-core-utilities//${{ matrix.project }}
run: |
sam build
sam validate --lint
- name: Setup Terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 #v2.0.3
- name: Run Terraform validator to check syntax of IaC templates and produce a plan of changes
working-directory: examples/powertools-examples-core-utilities/terraform
run: |
mvn install
terraform -version
terraform init -backend=false
terraform validate
- name: Setup Terraform lint
uses: terraform-linters/setup-tflint@a5a1af8c6551fb10c53f1cd4ba62359f1973746f # v3.1.1
- name: Run Terraform lint to check for best practices, errors, deprecated syntax etc.
working-directory: examples/powertools-examples-core-utilities/terraform
run: |
tflint --version
tflint --init
tflint -f compact
3 changes: 0 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,6 @@ Use the following [dependency matrix](https://github.com/eclipse-aspectj/aspectj
| `11-17` | `1.9.20.1` |
| `21` | `1.9.21` |

_Note: 1.9.21 is not yet available and Java 21 not yet officially supported by aspectj, but you can already use the `1.9.21.M1`_


## Environment variables

!!! info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,43 @@
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.nio.charset.StandardCharsets;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class AppStream implements RequestStreamHandler {
private static final ObjectMapper mapper = new ObjectMapper();
private final static Logger log = LogManager.getLogger(AppStream.class);

@Override
@Logging(logEvent = true)
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
Map map = mapper.readValue(input, Map.class);
// RequestStreamHandler can be used instead of RequestHandler for cases when you'd like to deserialize request body or serialize response body yourself, instead of allowing that to happen automatically
// Note that you still need to return a proper JSON for API Gateway to handle
// See Lambda Response format for examples: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
public void handleRequest(InputStream input, OutputStream output, Context context) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)))) {

System.out.println(map.size());
log.info("Received: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapper.readTree(reader)));

writer.write("{\"body\": \"" + System.currentTimeMillis() + "\"} ");
} catch (IOException e) {
log.error("Something has gone wrong: ", e);
}
}
}

Original file line number Diff line number Diff line change
@@ -1,48 +0,0 @@
/*
* Copyright 2023 Amazon.com, Inc. or its affiliates.
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package cdk;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import software.amazon.awscdk.App;
import software.amazon.awscdk.assertions.Template;

public class CdkStackTest {

@Test
public void testStack() {
App app = new App();
CdkStack stack = new CdkStack(app, "test");

Template template = Template.fromStack(stack);

// There should be 2 lambda functions, one to handle regular input, and another for streaming
template.resourceCountIs("AWS::Lambda::Function", 2);

// API Gateway should exist
template.resourceCountIs("AWS::ApiGateway::RestApi", 1);

// API Gateway should have a path pointing to the regular Lambda
Map<String, String> resourceProperties = new HashMap<>();
resourceProperties.put("PathPart", "hello");
template.hasResourceProperties("AWS::ApiGateway::Resource", resourceProperties);

// API Gateway should have a path pointing to the streaming Lambda
resourceProperties = new HashMap<>();
resourceProperties.put("PathPart", "hellostream");
template.hasResourceProperties("AWS::ApiGateway::Resource", resourceProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,43 @@
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.nio.charset.StandardCharsets;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import software.amazon.lambda.powertools.logging.Logging;
import software.amazon.lambda.powertools.metrics.Metrics;

import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class AppStream implements RequestStreamHandler {
private static final ObjectMapper mapper = new ObjectMapper();
private final static Logger log = LogManager.getLogger(AppStream.class);

@Override
@Logging(logEvent = true)
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
Map map = mapper.readValue(input, Map.class);
// RequestStreamHandler can be used instead of RequestHandler for cases when you'd like to deserialize request body or serialize response body yourself, instead of allowing that to happen automatically
// Note that you still need to return a proper JSON for API Gateway to handle
// See Lambda Response format for examples: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
public void handleRequest(InputStream input, OutputStream output, Context context) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)))) {

System.out.println(map.size());
log.info("Received: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapper.readTree(reader)));

writer.write("{\"body\": \"" + System.currentTimeMillis() + "\"} ");
} catch (IOException e) {
log.error("Something has gone wrong: ", e);
}
}
}

2 changes: 1 addition & 1 deletion powertools-e2e-tests/handlers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
<jdk>[21,)</jdk>
</activation>
<properties>
<aspectj.version>1.9.21.M1</aspectj.version>
<aspectj.version>1.9.21</aspectj.version>
</properties>
</profile>
</profiles>
Expand Down

0 comments on commit 3a365cb

Please sign in to comment.