<!-- Love localstack? Please consider supporting our collective:
👉  https://opencollective.com/localstack/donate -->

# Type of request: This is a ...

[x ] bug report
[ ] feature request

# Detailed description
I am using localstack on Windows 10. I can create a lambda function, load it to localstack and invoke it via the CLI. But when I try to modify the permissions via the add-permission function it fails with a long stack dump and the dreaded 'botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://e06d84562302:0/"' error. After looking at the lambda container the environment variable 'LOCALSTACK_HOSTNAME' = 'e06d84562302' which leads me to believe either I have a configuration issue or there is a translation that is not occurring in the add-permissions.

## Expected behavior
A success message.

## Actual behavior
The add-permissions function returns: 

An error occurred (500) when calling the AddPermission operation (reached max retries: 2): 
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"
500 Internal Server Error
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

In the log is a long stack dump and the error: 
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://e06d84562302:0/"

When examining the lambda container, the environment variable 'LOCALSTACK_HOSTNAME' = 'e06d84562302'

The e value will change if the current lambda is destroyed and a new lambda is created, but the error and the LOCALSTACK_HOSTNAME always match.

# Steps to reproduce
1) Start localstack via 'docker-compose up -d' command. The docker-compose.yml is listed below.
This succeeds.

2) Start lambda function via:
_awslocal_ lambda create-function --function-name ambProcessUASsim --zip-file fileb://./artifact/ambProcessUASsim.zip --handler=ambProcessUASsim::ambProcessUASsim.Function::FunctionHandler --runtime dotnetcore3.1 --role somerole --environment "Variables={Runtime=Debug,S3Port=4566}"_
This succeeds.

3) Create S3 bucket (if it does not already exist):
_awslocal s3 mb s3://demo-bucket_
This succeeds.

4) Add a permission via:
_awslocal lambda add-permission --function-name ambProcessUASsim  --action "lambda:InvokeFunction" --principal s3.amazonaws.com --source-arn arn:aws:s3:::demo-bucket --statement-id 1_

This fails with:
An error occurred (500) when calling the AddPermission operation (reached max retries: 2): 
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"
500 Internal Server Error
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

## Command used to start LocalStack
docker-compose.yml:
version: '3.7'

services:
  localstack-s3:
    image: localstack/localstack-full:latest
    container_name: localstack
    environment:
     - SERVICES=s3,dynamodb,lambda,sqs
     - DEBUG=1
     - DEFAULT_REGION=us-east-1
     - DATA_DIR=/tmp/localstack/data
     - HOST_TMP_FOLDER=${TMPDIR}
     - LAMBDA_EXECUTOR=docker-reuse
     - LAMBDA_REMOTE_DOCKER=false
     - DOCKER_HOST=unix:///var/run/docker.sock
     - START_WEB=1
     - PORT_WEB_UI=8080
    ports:
     - "4563-4599:4563-4599"
     - "8080:8080"
    volumes:
      - type: bind
        source: /d/tmp/localstack
        target: /tmp/localstack
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "sqs:/tmp/localstack/sqs"
    networks:
      - localstack_default

volumes:
  sqs: null
  localstack-data:
    name: localstack-data

networks:
  localstack_default:
    name: localstack_default
    driver: bridge


## Client code (AWS SDK code snippet, or sequence of "awslocal" commands)
The code is C# using the basic Visual Studio 2019 lambda template code for invoking from S3.

The only meaningful change is to create a local S3Client from environment variables.
```
var ddbconfig = new AmazonS3Config();
var ddbport = Environment.GetEnvironmentVariable("S3Port") ?? "4566";
var hostname = Environment.GetEnvironmentVariable("LOCALSTACK_HOSTNAME") ?? "http://localhost:";
ddbconfig.ServiceURL = string.Format("http://{0}:{1}", hostname, ddbport);
S3Client = new AmazonS3Client(ddbconfig);

```



if func_details.dead_letter_config:
        result['DeadLetterConfig'] = func_details.dead_letter_config
    if func_details.envvars:
        result['Environment'] = {
            'Variables': func_details.envvars
        }
    if (always_add_version or version != VERSION_LATEST) and len(result['FunctionArn'].split(':')) <= 7:
        result['FunctionArn'] += ':%s' % version
    return result
def forward_to_fallback_url(func_arn, data):
    """ If LAMBDA_FALLBACK_URL is configured, forward the invocation of this non-existing
        Lambda to the configured URL. """
    if not config.LAMBDA_FALLBACK_URL:
        return None
    lambda_name = aws_stack.lambda_function_name(func_arn)
    if config.LAMBDA_FALLBACK_URL.startswith('dynamodb://'):
        table_name = urlparse(config.LAMBDA_FALLBACK_URL.replace('dynamodb://', 'http://')).netloc
        dynamodb = aws_stack.connect_to_service('dynamodb')
        item = {
            'id': {'S': short_uid()},
            'timestamp': {'N': str(now_utc())},
            'payload': {'S': str(data)},
            'function_name': {'S': lambda_name}
        }
        aws_stack.create_dynamodb_table(table_name, partition_key='id')
        dynamodb.put_item(TableName=table_name, Item=item)
        return ''
    if re.match(r'^https?://.+', config.LAMBDA_FALLBACK_URL):
        headers = {'lambda-function-name': lambda_name}
        response = safe_requests.post(config.LAMBDA_FALLBACK_URL, data, headers=headers)