Dynamodb endpoint URL

Hello.

So I’m trying to setup a test project…Where I have an app that invokes lambda - which in turn writes to a dynamoDB table.

My main issue is that I face an error “could not connect to dynamoDB endpoint URL”, when running my lambda function.

However the endpoint specified is indeed correct, As I can run DynamoDB queries from my CLI…However the same endpoint does not work in lambda.

Please assist, Or point me in the right direction.

Hi @clinton.bitcoin,

If you are using community version, you will have to setup follow the configuration mentioned here Transparent Endpoint Injection | Docs (localstack.cloud)

In the community (open source) edition, the application code needs to configure each AWS SDK client instance with the target endpoint URL to point to the APIs on localhost or, in the case of Lambdas running in the context of LocalStack, the endpoint URL should point to http://${LOCALSTACK_HOSTNAME}:${EDGE_PORT}.

Thank you Marcel for your reply.
I have tried that, However I am still faced with the error: below is my first few lines of code:

def handler(event, context):
    clientconnection = boto3.client("dynamodb", endpoint_url="http://localhost:4566")

Something else I have also tried was : boto3.resource(…, instead of boto3.client However this also doesn’t help.

Hi,

You will need to use the environment variable as mentioned in Python Boto3 | Docs (localstack.cloud) or in the previously mentioned article.

import os
endpoint_url = f"http://{os.getenv("LOCALSTACK_HOSTNAME")}:{os.getenv("EDGE_PORT")}"
client = boto3.client("lambda", endpoint_url=endpoint_url)
1 Like

Hey Clinton, if you’re using the Community edition, take a quick look at these two gists:

Thank you Marcel, You suggestion has helped