diff --git a/.github/workflows/aws-lambda-main.yml b/.github/workflows/aws-lambda-main.yml index 23394002..93595b13 100644 --- a/.github/workflows/aws-lambda-main.yml +++ b/.github/workflows/aws-lambda-main.yml @@ -36,10 +36,3 @@ jobs: - name: Build with Maven run: ./mvnw clean verify - - - if: ${{ github.ref == 'refs/heads/main' }} - name: Build and Publish Docker Image - run: | - docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} - ./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=${{ secrets.DOCKER_USERNAME }}/aws-lambda-project-${{ matrix.java }} - docker push ${{ secrets.DOCKER_USERNAME }}/aws-lambda-project-${{ matrix.java }} diff --git a/aws-lambda-project/README.md b/aws-lambda-project/README.md new file mode 100644 index 00000000..572e3951 --- /dev/null +++ b/aws-lambda-project/README.md @@ -0,0 +1,2 @@ +# aws-lambda + diff --git a/aws-lambda-project/pom.xml b/aws-lambda-project/pom.xml index 3eca249d..c7e3db1c 100644 --- a/aws-lambda-project/pom.xml +++ b/aws-lambda-project/pom.xml @@ -1,135 +1,157 @@ - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.1.5 - - - com.example.awsspring - aws-lambda-project - 0.0.1-SNAPSHOT - aws-lambda-project-project - Demo project for Spring Boot - - 17 - 2022.0.4 - 1.0.29.RELEASE - 2.21.24 - 4.0.4 - 1.19.3 - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.cloud - spring-cloud-function-adapter-aws - - - org.springframework.boot - spring-boot-starter-data-jdbc - - - org.flywaydb - flyway-core - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.2.0-RC2 + + + com.example.awsspring + aws-lambda-project + 0.0.1-SNAPSHOT + aws-lambda-project-project + Demo project for Spring Boot - - org.postgresql - postgresql - runtime - - - org.springframework.boot - spring-boot-starter-test - test - - - org.testcontainers - junit-jupiter - test - - - org.testcontainers - localstack - test - - - org.testcontainers - postgresql - test - - - software.amazon.awssdk - lambda - - - org.apache.maven.shared - maven-invoker - 3.2.0 - test - - - io.rest-assured - rest-assured - test - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - software.amazon.awssdk - bom - ${aws.java.sdk.version} - pom - import - - - + + 17 + 2023.0.0-RC1 + 1.0.31.RELEASE + 2.21.24 + - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.springframework.boot.experimental - spring-boot-thin-layout - 1.0.31.RELEASE - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.2.4 - - false - true - aws - - - - + + + org.springframework.boot + spring-boot-starter + + + org.springframework.cloud + spring-cloud-function-adapter-aws + + + org.springframework.boot + spring-boot-starter-data-jdbc + + + org.flywaydb + flyway-core + + + software.amazon.awssdk + lambda + + + org.postgresql + postgresql + runtime + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.testcontainers + junit-jupiter + test + + + org.testcontainers + localstack + test + + + org.testcontainers + postgresql + test + + + org.apache.maven.shared + maven-invoker + 3.2.0 + test + + + io.rest-assured + rest-assured + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + software.amazon.awssdk + bom + ${aws.java.sdk.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.springframework.boot.experimental + spring-boot-thin-layout + ${wrapper.version} + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + false + true + aws + + + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + diff --git a/aws-lambda-project/src/test/java/com/example/springcloudfunctionaws/SpringCloudFunctionAwsApplicationTests.java b/aws-lambda-project/src/test/java/com/example/springcloudfunctionaws/SpringCloudFunctionAwsApplicationTests.java index af87c36f..8e8c846d 100644 --- a/aws-lambda-project/src/test/java/com/example/springcloudfunctionaws/SpringCloudFunctionAwsApplicationTests.java +++ b/aws-lambda-project/src/test/java/com/example/springcloudfunctionaws/SpringCloudFunctionAwsApplicationTests.java @@ -1,17 +1,19 @@ package com.example.springcloudfunctionaws; import io.restassured.RestAssured; -import io.restassured.response.ResponseBody; import org.apache.commons.io.FileUtils; import org.apache.maven.shared.invoker.DefaultInvocationRequest; import org.apache.maven.shared.invoker.DefaultInvoker; import org.apache.maven.shared.invoker.MavenInvocationException; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.util.StringUtils; import org.testcontainers.DockerClientFactory; import org.testcontainers.containers.Network; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.localstack.LocalStackContainer; +import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; @@ -22,7 +24,16 @@ import software.amazon.awssdk.core.waiters.WaiterResponse; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.lambda.LambdaClient; -import software.amazon.awssdk.services.lambda.model.*; +import software.amazon.awssdk.services.lambda.model.CreateFunctionRequest; +import software.amazon.awssdk.services.lambda.model.CreateFunctionResponse; +import software.amazon.awssdk.services.lambda.model.CreateFunctionUrlConfigRequest; +import software.amazon.awssdk.services.lambda.model.CreateFunctionUrlConfigResponse; +import software.amazon.awssdk.services.lambda.model.Environment; +import software.amazon.awssdk.services.lambda.model.FunctionCode; +import software.amazon.awssdk.services.lambda.model.FunctionUrlAuthType; +import software.amazon.awssdk.services.lambda.model.GetFunctionConfigurationRequest; +import software.amazon.awssdk.services.lambda.model.GetFunctionConfigurationResponse; +import software.amazon.awssdk.services.lambda.model.PackageType; import software.amazon.awssdk.services.lambda.model.Runtime; import java.io.File; @@ -40,6 +51,7 @@ @Testcontainers(parallel = true) class SpringCloudFunctionAwsApplicationTests { + private static final Logger LOGGER = LoggerFactory.getLogger(SpringCloudFunctionAwsApplicationTests.class); static String jar = buildJar(); static Network network = Network.newNetwork(); @@ -55,9 +67,9 @@ class SpringCloudFunctionAwsApplicationTests { .withEnv("LOCALSTACK_HOST", "localhost.localstack.cloud") .withEnv("LAMBDA_DOCKER_NETWORK", ((Network.NetworkImpl) network).getName()) .withNetworkAliases("localstack") - .withEnv("LAMBDA_DOCKER_FLAGS", testcontainersLabels()); + .withEnv("LAMBDA_DOCKER_FLAGS", testContainersLabels()); - static String testcontainersLabels() { + static String testContainersLabels() { return Stream .of(DockerClientFactory.DEFAULT_LABELS.entrySet().stream(), ResourceReaper.instance().getLabels().entrySet().stream()) @@ -89,6 +101,9 @@ static String buildJar() { @Test void contextLoads() throws IOException { + Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(LOGGER); + localstack.followOutput(logConsumer); + String fnName = "fetchByName-fn"; var envVars = Map.ofEntries(Map.entry("SPRING_DATASOURCE_URL", "jdbc:postgresql://postgres:5432/test"), Map.entry("SPRING_DATASOURCE_USERNAME", postgres.getUsername()), Map.entry("SPRING_DATASOURCE_PASSWORD", postgres.getPassword())); @@ -113,8 +128,10 @@ void contextLoads() throws IOException { .build(); CreateFunctionResponse createFunctionResponse = lambdaClient.createFunction(createFunctionRequest); + LOGGER.info("createFunctionResponse :{}", createFunctionResponse); WaiterResponse waiterResponse = lambdaClient.waiter() .waitUntilFunctionActive(GetFunctionConfigurationRequest.builder().functionName(fnName).build()); + LOGGER.info("waiterResponse :{}", waiterResponse); CreateFunctionUrlConfigRequest createFunctionUrlConfigRequest = CreateFunctionUrlConfigRequest.builder() .functionName(fnName) @@ -124,10 +141,15 @@ void contextLoads() throws IOException { String functionUrl = createFunctionUrlConfigResponse.functionUrl() .replace("" + 4566, "" + localstack.getMappedPort(4566)); - ResponseBody responseBody = RestAssured.given().body(""" + LOGGER.info("functionURL :{}", functionUrl); + var responseBody = RestAssured.given().body(""" {"name": "profile"} """).get(functionUrl).prettyPeek().andReturn().body(); assertThat(responseBody.asString()).isEqualTo("4"); + responseBody = RestAssured.given().body(""" + {"name": "junit"} + """).get(functionUrl).prettyPeek().andReturn().body(); + assertThat(responseBody.asString()).isEqualTo("0"); } }