diff --git a/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3InstallationService.java b/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3InstallationService.java index 5aaa58b85..b406219d9 100644 --- a/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3InstallationService.java +++ b/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3InstallationService.java @@ -30,15 +30,19 @@ public class AmazonS3InstallationService implements InstallationService { private boolean historicalDataEnabled; public AmazonS3InstallationService(String bucketName) { + this(bucketName, null); + } + + public AmazonS3InstallationService(String bucketName, AwsCredentialsProvider credentialsProvider) { this.bucketName = bucketName; + this.credentialsProvider = credentialsProvider; } @Override public Initializer initializer() { return (app) -> { // The first access to S3 tends to be slow on AWS Lambda. - this.credentialsProvider = DefaultCredentialsProvider.create(); - AwsCredentials credentials = createCredentials(credentialsProvider); + AwsCredentials credentials = createCredentials(getAwsCredentialsProvider()); if (credentials == null || credentials.accessKeyId() == null) { throw new IllegalStateException("AWS credentials not found"); } @@ -299,6 +303,13 @@ private Installer toInstaller(ResponseBytes s3Object) throws return JsonOps.fromJson(json, DefaultInstaller.class); } + protected AwsCredentialsProvider getAwsCredentialsProvider() { + if (this.credentialsProvider == null) { + this.credentialsProvider = DefaultCredentialsProvider.create(); + } + return this.credentialsProvider; + } + protected AwsCredentials createCredentials(AwsCredentialsProvider provider) { return provider.resolveCredentials(); } diff --git a/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3OAuthStateService.java b/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3OAuthStateService.java index 83760ea35..9f982a226 100644 --- a/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3OAuthStateService.java +++ b/bolt/src/main/java/com/slack/api/bolt/service/builtin/AmazonS3OAuthStateService.java @@ -26,15 +26,19 @@ public class AmazonS3OAuthStateService implements OAuthStateService { private AwsCredentialsProvider credentialsProvider; public AmazonS3OAuthStateService(String bucketName) { + this(bucketName, null); + } + + public AmazonS3OAuthStateService(String bucketName, AwsCredentialsProvider credentialsProvider) { this.bucketName = bucketName; + this.credentialsProvider = credentialsProvider; } @Override public Initializer initializer() { return (app) -> { // The first access to S3 tends to be slow on AWS Lambda. - this.credentialsProvider = DefaultCredentialsProvider.create(); - AwsCredentials credentials = createCredentials(credentialsProvider); + AwsCredentials credentials = createCredentials(getAwsCredentialsProvider()); if (credentials == null || credentials.accessKeyId() == null) { throw new IllegalStateException("AWS credentials not found"); } @@ -98,6 +102,13 @@ public void deleteStateFromDatastore(String state) throws Exception { } } + protected AwsCredentialsProvider getAwsCredentialsProvider() { + if (this.credentialsProvider == null) { + this.credentialsProvider = DefaultCredentialsProvider.create(); + } + return this.credentialsProvider; + } + protected AwsCredentials createCredentials(AwsCredentialsProvider provider) { return provider.resolveCredentials(); }