application.yml properties not recognized in Quarkus HTTP Lambda project

Viewed 373

I have a problem with getting requests targeting my local DynamoDB instance to work from Quarkus HTTP Lambda app. My local DynamoDB instance is running locally on http://localhost:8000 and this is what I see on startup:

Initializing DynamoDB Local with the following configuration:
Port:   8000
InMemory:   false
DbPath: null
SharedDb:   true
shouldDelayTransientStatuses:   false
CorsParams: *

After this I would start my lambda function by running:

mvn clean install
sam local start-api --template ./target/sam.jvm.yaml

On startup I would get the warnings that the properties from src/main/resources/application.yml file are unrecognized, even though I have quarkus-amazon-lambda-http and the software.amazon.awssdk.dynamodb dependencies on the classpath:

2021-08-24 14:04:10,886 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.dynamodb.aws.credentials.static-provider.access-key-id" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
2021-08-24 14:04:10,887 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.dynamodb.aws.region" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
2021-08-24 14:04:10,888 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.dynamodb.endpoint-override" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
2021-08-24 14:04:10,889 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.dynamodb.aws.credentials.type" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
2021-08-24 14:04:10,890 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.dynamodb.sync-client.type" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo
2021-08-24 14:04:10,891 WARN  [io.qua.config] (main) Unrecognized configuration key "quarkus.dynamodb.aws.credentials.static-provider.secret-access-key" was provided; it will be ignored; verify that the dependency extension for this configuration is set or that you did not make a typo

application.yml

quarkus:
  dynamodb:
    sync-client:
      type: apache
    aws:
      credentials:
        static-provider:
          access-key-id: test-key
          secret-access-key: test-secret
        type: static
      region: eu-south-1
    endpoint-override: http://localhost:8000

What is weird to me is that these properties are successfully loaded when using @ConfigProperty annotation. For example @ConfigProperty(name = "quarkus.dynamodb.endpoint-override") gives the correct value as specified in the application.yml file.

This is how the pom.xml looks:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.quarkus.platform</groupId>
                <artifactId>quarkus-bom</artifactId>
                <version>2.1.3.Final</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>software.amazon.awssdk</groupId>
                <artifactId>bom</artifactId>
                <version>2.17.19</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!-- remove if not using jaxrs -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-amazon-lambda-http</artifactId>
        </dependency>

        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-config-yaml</artifactId>
        </dependency>

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>apache-client</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-apache-httpclient</artifactId>
        </dependency>

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>dynamodb</artifactId>
        </dependency>

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>url-connection-client</artifactId>
        </dependency>

        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>dynamodb-enhanced</artifactId>
            <version>2.17.19</version>
        </dependency>

    </dependencies>

This is the service where the exception is thrown:

package com.dteam.service;

import com.dteam.model.Account;
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient;
import software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable;
import software.amazon.awssdk.enhanced.dynamodb.TableSchema;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;

import javax.enterprise.context.ApplicationScoped;
import javax.transaction.Transactional;

@Transactional
@ApplicationScoped
public class AccountService {

    public void createNewAccount() {
        Region region = Region.EU_SOUTH_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .httpClient(ApacheHttpClient.builder().build())
                .build();

        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
                .dynamoDbClient(ddb)
                .build();

        Account acc = new Account();
        acc.setEmail("example@mail.com");
        acc.setFirstName("Peter");
        acc.setLastName("Peterson");

        DynamoDbTable<Account> accTable = enhancedClient.table("Account", TableSchema.fromBean(Account.class));
        accTable.putItem(acc);
    }

}

After I trigger the AccountService#createNewAccount method, I get the following output in the terminal:

Caused by: software.amazon.awssdk.services.dynamodb.model.DynamoDbException: The security token 
included in the request is invalid. (Service: DynamoDb, Status Code: 400, Request ID: 
8V83KF73BH52NH4C4V9NM0LOSVVV4KQNSO5AEMVJF66Q9ASUAAJG, Extended Request ID: null)

What could I be missing that the properties from application.yml won't get recognized by quarkus? May I mention that I followed this guide when creating this project.

0 Answers
Related