sumanth shetty
sumanth shetty

Reputation: 2181

lambda function to query DynamoDB present in another region?

I am wondering if we can write a lambda function in one region for example us-east-1 to query a DynamoDB database present in another region.

I feel that there is a provision. just wondering how the syntax would be to achieve this.

dynamo_client = boto3.resource('dynamodb')
dynamo_table = dynamo_client.Table('table')

Above is a normal example of a dynamodb connection in the same region.

Wondering how would be the syntax when we want to access the dynamodb from another region.

Thank you

Upvotes: 3

Views: 3863

Answers (2)

smac2020
smac2020

Reputation: 10704

Yes you can. In your Lambda code - you can still set the Region for the DynamoDB Service Client. Consider this Java example:

// Create a DynamoDbClient object
 Region region = Region.US_WEST_2;
 DynamoDbClient ddb = DynamoDbClient.builder()
            .region(region)
            .build();

Now you can interact with a DynamoDB table located in US-WEST_2 region.

Upvotes: 2

Marcin
Marcin

Reputation: 238139

Yes, you can. resource takes region_name parameter:

dynamo_client = boto3.resource('dynamodb', region_name='<your-other-regio>')
dynamo_table = dynamo_client.Table('table')

Upvotes: 6

Related Questions