-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade to latest Scanamo version (1.0.0-M28)
Here we're moving up from Scanamo 1.0.0-M9 to 1.0.0-M28, which involves several changes to requirements: * AWS SDK v1 → v2 - Scanamo 1.0-M13 and above require AWS SDK v2 * Scanamo API changes: - When we `exec()` a Scanamo call, we now access an _instance_ of Scanamo that _wraps_ an AWS DynamoDB client, rather than supplying an AWS DynamoDB client to the `Scanamo` singleton. This means most of the `DataStore` classes in `media-atom-maker` now accept a `Scanamo` instance rather than a `AmazonDynamoDBClient`. - Auto-generated `DynamoFormat` handlers are now created by `org.scanamo.generic.auto._` rather than `org.scanamo.auto._` - Query on entity keys by name as a String (`"id"`), rather than using the old 'Symbol' apostrophe syntax (`'id`), and use `===` rather than `->` to specify the required key value. The AWS SDK v1 → v2 requirement of Scanamo is the tricky one to handle- a lot of code `media-atom-maker` also makes AWS SDK calls, and I didn't want to have to fix all of it to use AWS SDK v2 in this change. Instead, this change introduces `com.gu.media.aws.CredentialsForBothSdkVersions`, which makes a choice of AWS SDK v1 or v2 credentials available in the already-existing `com.gu.media.aws.AwsCredentials` class. This allows a partial move to AWS SDK v2, while other parts of the code remain on AWS SDK v1 for now. Notably, we need both v1 _and_ v2 versions of the DynamoDB client, as the atom-maker libraries in https://github.com/guardian/atom-maker still use AWS SDK v1.
- Loading branch information
Showing
20 changed files
with
155 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.gu.media.aws | ||
|
||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider | ||
import software.amazon.awssdk.awscore.client.builder.{AwsClientBuilder, AwsSyncClientBuilder} | ||
import software.amazon.awssdk.http.apache.ApacheHttpClient | ||
import software.amazon.awssdk.regions.Region | ||
|
||
object AwsV2Util { | ||
def buildSync[T, B <: AwsClientBuilder[B, T] with AwsSyncClientBuilder[B, T]]( | ||
builder: B, creds: AwsCredentialsProvider, region: Region | ||
): T = builder | ||
.httpClientBuilder(ApacheHttpClient.builder()) | ||
.credentialsProvider(creds) | ||
.region(region) | ||
.build() | ||
} |
48 changes: 48 additions & 0 deletions
48
common/src/main/scala/com/gu/media/aws/CredentialsForBothSdkVersions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.gu.media.aws | ||
|
||
import com.amazonaws.auth._ | ||
import com.amazonaws.auth.profile.ProfileCredentialsProvider | ||
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder | ||
import software.amazon.awssdk.auth.{credentials => awsv2} | ||
import software.amazon.awssdk.regions.Region | ||
import software.amazon.awssdk.services.sts.{StsClient, StsClientBuilder} | ||
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest | ||
|
||
case class CredentialsForBothSdkVersions( | ||
awsV1Creds: com.amazonaws.auth.AWSCredentialsProvider, | ||
awsV2Creds: software.amazon.awssdk.auth.credentials.AwsCredentialsProvider | ||
) { | ||
def assumeAccountRole(roleArn: String, sessionNameSuffix: String, regionName: String): CredentialsForBothSdkVersions = { | ||
val roleSessionName = s"media-atom-maker-$sessionNameSuffix" | ||
CredentialsForBothSdkVersions( | ||
new STSAssumeRoleSessionCredentialsProvider.Builder(roleArn, roleSessionName) | ||
.withStsClient(AWSSecurityTokenServiceClientBuilder.standard().withCredentials(awsV1Creds).build()).build(), | ||
software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider.builder() | ||
.stsClient(AwsV2Util.buildSync[StsClient, StsClientBuilder](StsClient.builder(), awsV2Creds, Region.of(regionName))) | ||
.refreshRequest(AssumeRoleRequest.builder.roleSessionName(roleSessionName).roleArn(roleArn).build) | ||
.build() | ||
) | ||
} | ||
} | ||
|
||
object CredentialsForBothSdkVersions { | ||
def profile(name: String): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
new ProfileCredentialsProvider(name), | ||
awsv2.ProfileCredentialsProvider.create(name) | ||
) | ||
|
||
def instance(): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
InstanceProfileCredentialsProvider.getInstance(), | ||
awsv2.InstanceProfileCredentialsProvider.create() | ||
) | ||
|
||
def environmentVariables(): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
new EnvironmentVariableCredentialsProvider(), | ||
awsv2.EnvironmentVariableCredentialsProvider.create() | ||
) | ||
|
||
def static(accessKey: String, secretKey: String): CredentialsForBothSdkVersions = CredentialsForBothSdkVersions( | ||
new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)), | ||
awsv2.StaticCredentialsProvider.create(awsv2.AwsBasicCredentials.create(accessKey, secretKey)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.