sumanth shetty
sumanth shetty

Reputation: 2181

Connect to DynamDB using python language in Lambda function

I am families with working of Lambda function. But the thing here is i am trying to figure out how can i establish connection with my DynamDB using python.

dynamodb = boto3.resource('dynamodb', endpoint_url="http://localhost:8000")

I found this above code , but this is when i am using AWS SDK.

My use case is to have a sever less have a API set up to trigger a Lambda function to operate CRUD function DynamoDB.

Could some one suggest me a way to connect to my DynamoDB which is present in us-east-1?

Upvotes: 1

Views: 85

Answers (1)

Chris Williams
Chris Williams

Reputation: 35156

The sample you have is for connecting to a local DynamoDB.

To do this for a region it is as simple as using the below

dynamodb = boto3.client('dynamodb', region_name="us-east-1")

Alternatively you can set this in the session using the below example

boto3.setup_default_session(region_name="us-east-1")

I would suggest to take a look at using an environment variable to set the region you call here so that you could reuse in other regions in the future with a bit of ease.

Upvotes: 1

Related Questions