/* * 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.enhanced.dynamodb.DynamoDbEnhancedClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.dynamodb.DynamoDbClient; import java.net.URI; @Configuration public class AppConfig { public final static Integer APPLICATION_VERSION = 1; @Value("${amazon.dynamodb.endpoint}") private String amazonDynamoDBEndpoint; @Bean public DynamoDbClient getDynamoDbClient() { AwsCredentialsProvider credentialsProvider = DefaultCredentialsProvider.builder() .profileName("default") .build(); return DynamoDbClient.builder() .region(Region.EU_WEST_1) .credentialsProvider(credentialsProvider) .endpointOverride(URI.create(amazonDynamoDBEndpoint)) .build(); } @Bean public DynamoDbEnhancedClient getDynamoDbEnhancedClient() { return DynamoDbEnhancedClient.builder() .dynamoDbClient(getDynamoDbClient()) .build(); } }