Last active
April 25, 2023 22:50
-
-
Save mpatnode/607c401a4e85352630803d568e989b7a to your computer and use it in GitHub Desktop.
Allow localstack Python lambda functions to talk to localstack:4566 vs AWS. Grab a copy of session.py, apply the patch and mount it into the LAMBDA docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
""" | |
+ if endpoint_url is None: | |
+ endpoint_url = os.environ.get("AWS_ENDPOINT_URL") | |
+ | |
return self._session.create_client( | |
service_name, | |
region_name=region_name, | |
~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
- "4510-4600:4510-4600" | |
environment: | |
- ACTIVATE_PRO=0 | |
- HOSTNAME=localstack | |
- LOCALSTACK_HOST=host.docker.internal | |
- LAMBDA_DOCKER_FLAGS=--add-host $BRITIVE_LOCAL_DEVELOPMENT_AWS_RESOURCE_PREFIX-es-cluster.$DEFAULT_REGION.es.localhost.localstack.cloud:host-gateway | |
--add-host localstack:host-gateway | |
--add-host mysql:host-gateway | |
-e AWS_ENDPOINT_URL=http://localstack:4566 | |
-v $BRITIVE_LOCAL_DEVELOPMENT_LOCAL_DEV_DIR/data/python/boto/session.py:/var/runtime/boto3/session.py | |
# - LS_LOG=trace | |
# - DEBUG=1 | |
extra_hosts: # Required for Linux/AWS Workstation | |
- "host.docker.internal:host-gateway" | |
- "$BRITIVE_LOCAL_DEVELOPMENT_AWS_RESOURCE_PREFIX-es-cluster.$DEFAULT_REGION.es.localhost.localstack.cloud:host-gateway" | |
volumes: | |
- $BRITIVE_LOCAL_DEVELOPMENT_LOCAL_DEV_DIR/data/localstack/podfiles:/mnt/data | |
- $BRITIVE_LOCAL_DEVELOPMENT_LOCAL_DEV_DIR/data/localstack/podload.sh:/etc/localstack/init/ready.d/podload.sh | |
- /var/run/docker.sock:/var/run/docker.sock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment