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:
Boto3 session.py patch
This is the latest session.py file from https://github.com/boto/boto3 version 1.26.118 with the following patch
to allow for the AWS_ENDPOINT_URL to override the defaults
~~~
diff --git a/boto3/session.py b/boto3/session.py
index bdda65ad..ba57fbb2 100644
--- a/boto3/session.py
+++ b/boto3/session.py
@@ -296,6 +296,9 @@ class Session:
:return: Service client instance
This file has been truncated. show original
docker-compose.yml
localstack:
container_name: localstack_main
hostname: localstack
image: localstack/localstack:2.0.2
profiles: ["localstack"]
mem_limit: 2g
sysctls:
- net.ipv4.tcp_tw_reuse=1
- net.ipv4.tcp_fin_timeout=10
ports:
This file has been truncated. show original
Thank you Marcel, You suggestion has helped