'Localstack and python and docker-compose strange behaviour
I have created a docker-compose file for localstack and I'm using only services like s3 and SQS. It works fine and I could create a dummy SQS, S3 from localstack using AWS CLI command and can reach the localstack container from outside. I have created SQS queue name called mytestqueue
Now, I have created this simple boto3, python script, and this python script is used as a new service to the existing local-stack docker-compose :
python3-boto3:
image: python/boto3:latest
container_name: boto3
environment:
- "AWS_ACCESS_KEY_ID=dummyaccess"
- "AWS_SECRET_ACCESS_KEY=dummysecret"
- "AWS_DEFAULT_REGION=eu-west-1"
- "AWS_ENDPOINT=http://localstack:443"
volumes:
- "$PWD:/usr/src/app/"
command: python /usr/src/app/boto3_python.py
Boto3Script boto3_python.py:
sqs_client = boto3.client("sqs",
region_name=os.environ.get('AWS_DEFAULT_REGION'),
endpoint_url=os.environ.get('AWS_ENDPOINT'),
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY'))
response = sqs_client.get_queue_url(QueueName='mytestqueue')
print(response)
Now the strange problem is happening: maybe there is an explanation but still can't figure it out.
Now if I run the docker-compose up command I'm getting the error The specified queue does not exist for this wsdl version. that means my Queue is not reachable from the container boto3 but now, if I get into this boto3 container and run this exact python script, then everything works fine, no URL issue.
So, can anyone tell me why in docker-compose this same script shows the URL can't be reachable while inside the container it works perfectly fine.
Solution 1:[1]
I have fixed this issue, by simply adding the sleep command in my python boto3 script.
If anyone has a similar issue, add the sleep command it will work. I'm not sure if there is any elegant solution exists but if anyone has please post here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | change198 |
