package com.simplerecipemanager.configuration;

import io.dropwizard.setup.Environment;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;

public class DynamoDBMapperFactory {

	private AWSCredentialsProvider stringProvider;

	public DynamoDBMapperFactory(String accessKey, String secretKey) {
		this.stringProvider = new AWSCredentialsProvider() {

			@Override
			public void refresh() {
			}

			@Override
			public AWSCredentials getCredentials() {
				return new AWSCredentials() {

					@Override
					public String getAWSSecretKey() {
						return secretKey;
					}

					@Override
					public String getAWSAccessKeyId() {
						return accessKey;
					}
				};
			}
		};
	}

	public DynamoDBMapper build(Environment environment) {
		AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(
				new InstanceProfileCredentialsProvider(), stringProvider);
		AmazonDynamoDBClient client = new AmazonDynamoDBClient(chain);
		return new DynamoDBMapper(client);
	}
}

@@ -229,16 +229,63 @@
 rChain;%0A
+import com.amazonaws.auth.BasicAWSCredentials;%0A
 import c
@@ -519,16 +519,22 @@
 private 
+final 
 AWSCrede
@@ -563,16 +563,59 @@
 rovider;
+%0A%09private final AWSCredentials stringCreds;
 %0A%0A%09publi
@@ -675,16 +675,85 @@
 etKey) %7B
+%0A%0A%09%09this.stringCreds = new BasicAWSCredentials(accessKey, secretKey);
 %0A%09%09this.
@@ -919,210 +919,46 @@
 urn 
-new AWSCredentials() %7B%0A%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public String getAWSSecretKey() %7B%0A%09%09%09%09%09%09return secretKey;%0A%09%09%09%09%09%7D%0A%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public String getAWSAccessKeyId() %7B%0A%09%09%09%09%09%09return accessKey;%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D
+DynamoDBMapperFactory.this.stringCreds
 ;%0A%09%09

Use BasicAWSCredentials