Skip to content

Fix AWS credentials forwarding #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,26 @@ Tests are implemented in the `tests` sbt submodule. They simulate the submission
sbt testOnly com.scylladb.migrator.BasicMigrationTest
~~~

Or, to run the tests that access AWS, first configure your AWS credentials with `aws configure`, and then:

~~~ sh
AWS_REGION=us-east-1 \
sbt "testOnly -- --include-categories=com.scylladb.migrator.AWS"
~~~
Or, to run the tests that access AWS:

1. Create an IAM test user and an IAM role to grant them access to your actual AWS account, according to [this tutorial](https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html).
2. Log-in as the test user in the CLI
3. Create temporary credentials via `aws sts assume-role`:
~~~ sh
aws sts assume-role --role-arn "your-role-arn" --role-session-name "scylla-migrator-test"
~~~
4. Export the resulting credentials in environment variables:
~~~ sh
export AWS_REGION=us-east-1
export AWS_ACCESS_KEY_ID=xxx
export AWS_SECRET_ACCESS_KEY=yyy
export AWS_SESSION_TOKEN=zzz
~~~
Where `xxx`, `yyy`, and `zzz` are the credentials returned by the `sts assume-role` command.
5. In the same shell, run the tests:
~~~ sh
sbt "testOnly -- --include-categories=com.scylladb.migrator.AWS"
~~~

4. Ultimately, stop the Docker containers

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ lazy val migrator = (project in file("migrator")).enablePlugins(BuildInfoPlugin)
"software.amazon.awssdk" % "sts" % awsSdkVersion,
"com.scylladb" %% "spark-scylladb-connector" % "4.0.0",
"com.github.jnr" % "jnr-posix" % "3.1.19", // Needed by the Spark ScyllaDB connector
"com.scylladb.alternator" % "emr-dynamodb-hadoop" % "5.7.1",
"com.scylladb.alternator" % "emr-dynamodb-hadoop" % "5.8.0",
"com.scylladb.alternator" % "load-balancing" % "1.0.0",
"io.circe" %% "circe-generic" % "0.14.7",
"io.circe" %% "circe-parser" % "0.14.7",
Expand Down
9 changes: 8 additions & 1 deletion docker-compose-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ services:
command: master
environment:
SPARK_PUBLIC_DNS: localhost
AWS_REGION: ${AWS_REGION}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN}
expose:
- 5005
ports:
Expand All @@ -63,7 +67,6 @@ services:
- ./migrator/target/scala-2.13:/jars
- ./tests/src/test/configurations:/app/configurations
- ./tests/docker/spark-master:/app/savepoints
- ./tests/docker/aws-profile:/root/.aws
- ./tests/docker/parquet:/app/parquet

spark-worker:
Expand All @@ -74,6 +77,10 @@ services:
SPARK_WORKER_MEMORY: 4G
SPARK_WORKER_WEBUI_PORT: 8081
SPARK_PUBLIC_DNS: localhost
AWS_REGION: ${AWS_REGION}
AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_SESSION_TOKEN: ${AWS_SESSION_TOKEN}
expose:
- 5006
ports:
Expand Down
4 changes: 0 additions & 4 deletions tests/docker/aws-profile/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
source:
type: dynamodb
table: StreamedItemsSkipSnapshotTest
table: migrator-StreamedItemsSkipSnapshotTest
region: us-east-1

target:
type: dynamodb
table: StreamedItemsSkipSnapshotTest
table: migrator-StreamedItemsSkipSnapshotTest
region: dummy
endpoint:
host: http://scylla
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
source:
type: dynamodb
table: StreamedItemsTest
table: migrator-StreamedItemsTest
region: us-east-1

target:
type: dynamodb
table: StreamedItemsTest
table: migrator-StreamedItemsTest
region: dummy
endpoint:
host: http://scylla
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,20 +198,7 @@ abstract class MigratorSuiteWithAWS extends MigratorSuite {
lazy val sourceDDb: Fixture[DynamoDbClient] = new Fixture[DynamoDbClient]("sourceDDb") {
private var client: DynamoDbClient = null
def apply(): DynamoDbClient = client
override def beforeAll(): Unit = {
// Provision the AWS credentials on the Spark nodes via a Docker volume
val localAwsCredentials =
Paths.get(sys.props("user.home"), ".aws", "credentials")
.toAbsolutePath
(s"cp ${localAwsCredentials} docker/aws-profile/credentials").!!

val region = Region.of(sys.env("AWS_REGION"))
client =
DynamoDbClient
.builder()
.region(region)
.build()
}
override def beforeAll(): Unit = client = DynamoDbClient.create()
override def afterAll(): Unit = client.close()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import scala.util.chaining.scalaUtilChainingOps

class StreamedItemsTest extends MigratorSuiteWithAWS {

override val munitTimeout: Duration = 120.seconds
override val munitTimeout: Duration = 600.seconds

withTable("StreamedItemsTest").test("Stream changes") { tableName =>
withTable("migrator-StreamedItemsTest").test("Stream changes") { tableName =>
val configFileName = "dynamodb-to-alternator-streaming.yaml"

// Populate the source table
Expand All @@ -27,7 +27,7 @@ class StreamedItemsTest extends MigratorSuiteWithAWS {
submitSparkJobProcess(configFileName, "com.scylladb.migrator.Migrator")
.run(ProcessLogger { log =>
sparkLogs ++= log
// println(log) // Uncomment to see the logs
println(log)
})

awaitAtMost(60.seconds) {
Expand All @@ -53,7 +53,7 @@ class StreamedItemsTest extends MigratorSuiteWithAWS {
sourceDDb().putItem(PutItemRequest.builder().tableName(tableName).item(item2Data.asJava).build())

// Check that the added item has also been migrated
awaitAtMost(60.seconds) {
awaitAtMost(300.seconds) {
targetAlternator()
.getItem(GetItemRequest.builder().tableName(tableName).key(keys2.asJava).build())
.tap { itemResult =>
Expand All @@ -71,7 +71,7 @@ class StreamedItemsTest extends MigratorSuiteWithAWS {
deleteStreamTable(tableName)
}

withTable("StreamedItemsSkipSnapshotTest").test("Stream changes but skip initial snapshot") { tableName =>
withTable("migrator-StreamedItemsSkipSnapshotTest").test("Stream changes but skip initial snapshot") { tableName =>
val configFileName = "dynamodb-to-alternator-streaming-skip-snapshot.yaml"

// Populate the source table
Expand All @@ -86,7 +86,7 @@ class StreamedItemsTest extends MigratorSuiteWithAWS {
submitSparkJobProcess(configFileName, "com.scylladb.migrator.Migrator")
.run(ProcessLogger { (log: String) =>
sparkLogs ++= log
// println(log) // Uncomment to see the logs
println(log)
})

// Wait for the changes to start being streamed
Expand All @@ -104,7 +104,7 @@ class StreamedItemsTest extends MigratorSuiteWithAWS {
sourceDDb().putItem(PutItemRequest.builder().tableName(tableName).item(item2Data.asJava).build())

// Check that only the second item has been migrated
awaitAtMost(60.seconds) {
awaitAtMost(300.seconds) {
targetAlternator()
.getItem(GetItemRequest.builder().tableName(tableName).key(keys2.asJava).build())
.tap { itemResult =>
Expand Down
Loading