Skip to content

Commit

Permalink
[closes #991] Add wait for IAM and DynamoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
avano committed Feb 27, 2025
1 parent 4f2e41e commit a956653
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public void createTable(String tableName, String primaryKey) {
.keySchema(KeySchemaElement.builder().attributeName(primaryKey).keyType(KeyType.HASH).build())
.attributeDefinitions(AttributeDefinition.builder().attributeType(ScalarAttributeType.S).attributeName(primaryKey).build())
);
WaitUtils.waitFor(
() -> "active".equalsIgnoreCase(client.describeTable(b -> b.tableName(tableName)).table().tableStatusAsString()),
6, 5000L, "Waiting until the DynamoDB table " + tableName + " is created");

client.waiter().waitUntilTableExists(b -> b.tableName(tableName));
}

public String enableDataStream(String tableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ public String createRole(String name, String description, String rolePolicyDocum
return getRoleArn(name).get();
} else {
LOG.debug("Creating IAM role {}", name);
return client.createRole(b -> b.roleName(name)
final String arn = client.createRole(b -> b.roleName(name)
.description(description)
.assumeRolePolicyDocument(rolePolicyDocument)
).role().arn();

client.waiter().waitUntilRoleExists(r -> r.roleName(name));

return arn;
}
}

public String createPolicy(String name, String policyDocument) {
return client.createPolicy(b -> b.policyName(name)
final String arn = client.createPolicy(b -> b.policyName(name)
.policyDocument(policyDocument)
).policy().arn();

client.waiter().waitUntilPolicyExists(b -> b.policyArn(arn));

return arn;
}

public void attachPolicy(String role, String policyArn) {
Expand Down

0 comments on commit a956653

Please sign in to comment.