Skip to content

Commit fe5318e

Browse files
Fall back to AWS credential chain (IAM role) for DynamoDB when no keys set (#1285) (#1289)
DynamoDBConnection always built the client via new AmazonDynamoDBClient(mCredentials, mConfig). When the datastore's User_id / User_password properties are left empty (to authenticate via the EC2 instance's IAM role), mCredentials is null and passing it explicitly prevents the AWS SDK from using its default credential resolution chain, so requests go out unsigned and fail with "Request is missing Authentication Token". Mirror what ExternalProviderS3 already does: - Only build BasicAWSCredentials when both User_id and User_password are present AND non-empty (previously a present-but-empty value produced empty credentials). - When there are no explicit credentials, use the config-only constructor new AmazonDynamoDBClient(mConfig), which engages the default credential chain (incl. the EC2 instance profile / IAM role). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 43300d3 commit fe5318e

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

dotnet/src/dotnetcommon/DynService.Dynamo/DynamoDBConnection.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ private void InitializeDBConnection()
5252
{
5353
mLocalUrl = localUrl.ToString();
5454
}
55-
if (builder.TryGetValue(CLIENT_ID, out object clientId) && builder.TryGetValue(CLIENT_SECRET, out object clientSecret))
55+
if (builder.TryGetValue(CLIENT_ID, out object clientId) && builder.TryGetValue(CLIENT_SECRET, out object clientSecret)
56+
&& !string.IsNullOrEmpty(clientId?.ToString()) && !string.IsNullOrEmpty(clientSecret?.ToString()))
5657
{
5758
mCredentials = new BasicAWSCredentials(clientId.ToString(), clientSecret.ToString());
5859
}
@@ -75,7 +76,12 @@ private void Initialize()
7576
{
7677
InitializeDBConnection();
7778
State = ConnectionState.Executing;
78-
mDynamoDB = new AmazonDynamoDBClient(mCredentials, mConfig);
79+
// When no explicit credentials are provided, use the config-only constructor so the
80+
// AWS default credential resolution chain (incl. the EC2 instance profile / IAM role)
81+
// kicks in, mirroring how ExternalProviderS3 builds its client.
82+
mDynamoDB = mCredentials != null
83+
? new AmazonDynamoDBClient(mCredentials, mConfig)
84+
: new AmazonDynamoDBClient(mConfig);
7985
}
8086

8187
private const string FILTER_PATTERN = @"\((.*) = :(.*)\)";

0 commit comments

Comments
 (0)