/* * Copyright 2010-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file 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 com.amazon.customerService.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import software.amazon.awssdk.services.dynamodb.DynamoDbClientBuilder; import java.net.URI; @Configuration public class AppConfig { public final static Integer APPLICATION_VERSION = 6; @Value("${amazon.dynamodb.endpoint}") private String amazonDynamoDBEndpoint; @Bean public DynamoDbClient getDynamoDbClient() { AwsCredentialsProvider credentialsProvider = DefaultCredentialsProvider.builder() .profileName("default") .build(); DynamoDbClientBuilder clientBuilder = DynamoDbClient.builder(); clientBuilder .credentialsProvider(credentialsProvider); if (!amazonDynamoDBEndpoint.isEmpty()) { clientBuilder.endpointOverride(URI.create(amazonDynamoDBEndpoint)); } return clientBuilder.build(); } }