internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: localstack/localstack

Issue:
ElasticSearch 6 Support
Is there a plan for ElasticSearch 6 support anytime soon? Since [AWS supports ES 6](https://aws.amazon.com/about-aws/whats-new/2017/12/elasticsearch-6-0-now-available-on-amazon-elasticsearch-service/) it would be nice to be able to effectively simulate it locally.


Discussion:

Resolving patch:
diff --git a/localstack/constants.py b/localstack/constants.py
--- a/localstack/constants.py
+++ b/localstack/constants.py
@@ -69,7 +69,7 @@
 LAMBDA_TEST_ROLE = 'arn:aws:iam::%s:role/lambda-test-role' % TEST_AWS_ACCOUNT_ID
 
 # installation constants
-ELASTICSEARCH_JAR_URL = 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.zip'
+ELASTICSEARCH_JAR_URL = 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.0.zip'
 DYNAMODB_JAR_URL = 'https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip'
 ELASTICMQ_JAR_URL = 'https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-0.13.8.jar'
 STS_JAR_URL = 'http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-sts/1.11.14/aws-java-sdk-sts-1.11.14.jar'
diff --git a/localstack/services/es/es_api.py b/localstack/services/es/es_api.py
--- a/localstack/services/es/es_api.py
+++ b/localstack/services/es/es_api.py
@@ -39,7 +39,7 @@ def get_domain_status(domain_name, deleted=False):
                 'InstanceType': 'm3.medium.elasticsearch',
                 'ZoneAwarenessEnabled': True
             },
-            'ElasticsearchVersion': '5.3',
+            'ElasticsearchVersion': '6.2',
             'Endpoint': None,
             'Processing': True
         }


Test patch:
Repository: localstack/localstack

Issue:
Firehose fails without S3DestinationConfiguration.Prefix 
Despite the AWS SDK not requiring a prefix, it seems like localstack fails without one:

```2018-05-14T17:28:43:ERROR:firehose_api: Exception on / [POST]
Traceback (most recent call last):
  File "/opt/code/localstack/.venv/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/opt/code/localstack/.venv/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/opt/code/localstack/.venv/lib/python2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/opt/code/localstack/.venv/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/opt/code/localstack/.venv/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/code/localstack/.venv/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/opt/code/localstack/localstack/services/firehose/firehose_api.py", line 183, in post_request
    put_record(stream_name, record)
  File "/opt/code/localstack/localstack/services/firehose/firehose_api.py", line 40, in put_record
    return put_records(stream_name, [record])
  File "/opt/code/localstack/localstack/services/firehose/firehose_api.py", line 63, in put_records
    prefix = s3_dest['Prefix']
KeyError: 'Prefix'```


Discussion:

Resolving patch:
diff --git a/localstack/services/firehose/firehose_api.py b/localstack/services/firehose/firehose_api.py
--- a/localstack/services/firehose/firehose_api.py
+++ b/localstack/services/firehose/firehose_api.py
@@ -60,12 +60,12 @@ def put_records(stream_name, records):
         if 'S3DestinationDescription' in dest:
             s3_dest = dest['S3DestinationDescription']
             bucket = bucket_name(s3_dest['BucketARN'])
-            prefix = s3_dest['Prefix']
+            prefix = s3_dest.get('Prefix', '')
             s3 = get_s3_client()
             for record in records:
                 data = base64.b64decode(record['Data'])
                 obj_name = str(uuid.uuid4())
-                obj_path = '%s%s' % (prefix, obj_name)
+                obj_path = '%s%s%s' % (prefix, '' if prefix.endswith('/') else '/', obj_name)
                 try:
                     s3.Object(bucket, obj_path).put(Body=data)
                 except Exception as e:


Test patch:
Repository: localstack/localstack

Issue:
Send SMS via SNS fails with 502
Hi, we are trying to mock the SMS sending via SMS.
```
aws --endpoint-url=http://localhost:4575 --region=us-east-1 sns publish --message "lorem ipsum" --phone-number 12345
```
Checking the localstack image I can see a Python error in the logs:
```
2018-10-30T13:46:19:ERROR:localstack.services.generic_proxy: Error forwarding request: None Traceback (most recent call last):
  File "/opt/code/localstack/localstack/services/generic_proxy.py", line 181, in forward
    path=path, data=data, headers=forward_headers)
  File "/opt/code/localstack/localstack/services/sns/sns_listener.py", line 68, in forward_request
    for subscriber in SNS_SUBSCRIPTIONS[topic_arn]:
KeyError: None
```
Checking the source code I can see that topic_arn is None because it is not informed in the SNS API Call. If I inform topic_arn everything works fine:
```
aws --endpoint-url=http://localhost:4575 --region=us-east-1 sns publish --message "lorem ipsum" --phone-number 12345 --topic-arn abcd
{
    "MessageId": "245292e5"
}
```

Can you guys please check that?
Thanks


Discussion:

Resolving patch:
diff --git a/localstack/services/sns/sns_listener.py b/localstack/services/sns/sns_listener.py
--- a/localstack/services/sns/sns_listener.py
+++ b/localstack/services/sns/sns_listener.py
@@ -65,7 +65,7 @@ def forward_request(self, method, path, data, headers):
             elif req_action == 'Publish':
                 message = req_data['Message'][0]
                 sqs_client = aws_stack.connect_to_service('sqs')
-                for subscriber in SNS_SUBSCRIPTIONS[topic_arn]:
+                for subscriber in SNS_SUBSCRIPTIONS.get(topic_arn, []):
                     filter_policy = json.loads(subscriber.get('FilterPolicy', '{}'))
                     message_attributes = get_message_attributes(req_data)
                     if check_filter_policy(filter_policy, message_attributes):


Test patch:
Repository: localstack/localstack

Issue:
Update code climate and badge
https://codeclimate.com/github/atlassian/localstack is the old repo, is there a new code climate check for the new repo?  The README is pointing to this old code climate project.


Discussion:
https://codeclimate.com/github/localstack/localstack is a 404

Resolving patch:
diff --git a/localstack/constants.py b/localstack/constants.py
--- a/localstack/constants.py
+++ b/localstack/constants.py
@@ -2,7 +2,7 @@
 import localstack_client.config
 
 # LocalStack version
-VERSION = '0.8.9'
+VERSION = '0.8.10'
 
 # default AWS region
 if 'DEFAULT_REGION' not in os.environ:


Test patch:
Repository: localstack/localstack

Issue:
Localstack Elasticsearch plugin Ingest User Agent Processor not available
Plugin `Ingest User Agent Processor` is installed by default for Elasticsearch (ELK) on AWS. It is not the case in Localstack and think we basically expect it.

In addition, I was not able to install it manually through command `bin/elasticsearch-plugin install ingest-user-agent` as bin/elasticsearch-plugin is missing.


Discussion:
Thanks for reporting @ericbdc - would you by any chance be able to provide a pull request with a fix? Thanks!

Resolving patch:
diff --git a/localstack/constants.py b/localstack/constants.py
--- a/localstack/constants.py
+++ b/localstack/constants.py
@@ -70,6 +70,9 @@
 
 # installation constants
 ELASTICSEARCH_JAR_URL = 'https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.0.zip'
+# https://docs.aws.amazon.com/ja_jp/elasticsearch-service/latest/developerguide/aes-supported-plugins.html
+ELASTICSEARCH_PLUGIN_LIST = ['analysis-icu', 'ingest-attachment', 'ingest-user-agent', 'analysis-kuromoji',
+ 'mapper-murmur3', 'mapper-size', 'analysis-phonetic', 'analysis-smartcn', 'analysis-stempel', 'analysis-ukrainian']
 DYNAMODB_JAR_URL = 'https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip'
 ELASTICMQ_JAR_URL = 'https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-0.14.2.jar'
 STS_JAR_URL = 'http://central.maven.org/maven2/com/amazonaws/aws-java-sdk-sts/1.11.14/aws-java-sdk-sts-1.11.14.jar'
diff --git a/localstack/services/install.py b/localstack/services/install.py
--- a/localstack/services/install.py
+++ b/localstack/services/install.py
@@ -7,7 +7,7 @@
 import logging
 import tempfile
 from localstack.constants import (DEFAULT_SERVICE_PORTS, ELASTICMQ_JAR_URL, STS_JAR_URL,
-    ELASTICSEARCH_JAR_URL, DYNAMODB_JAR_URL, LOCALSTACK_MAVEN_VERSION)
+    ELASTICSEARCH_JAR_URL, ELASTICSEARCH_PLUGIN_LIST, DYNAMODB_JAR_URL, LOCALSTACK_MAVEN_VERSION)
 from localstack.utils.common import download, parallelize, run, mkdir, save_file, unzip, rm_rf, chmod_r
 
 THIS_PATH = os.path.dirname(os.path.realpath(__file__))
@@ -47,6 +47,14 @@ def install_elasticsearch():
             mkdir(dir_path)
             chmod_r(dir_path, 0o777)
 
+        # install default plugins
+        for plugin in ELASTICSEARCH_PLUGIN_LIST:
+            if is_alpine():
+                # https://github.com/pires/docker-elasticsearch/issues/56
+                os.environ['ES_TMPDIR'] = '/tmp'
+            plugin_binary = os.path.join(INSTALL_DIR_ES, 'bin', 'elasticsearch-plugin')
+            run('%s install %s' % (plugin_binary, plugin))
+
 
 def install_elasticmq():
     if not os.path.exists(INSTALL_DIR_ELASTICMQ):


Test patch:
Repository: localstack/localstack

Issue:
Can't figure what endpoint to use for STS (get-caller-identity)
Basically I need `aws --endpoint=http://localhost:??? sts get-caller-identity` to work, it seems localstack can support that, but I can't figure the right endpoint/port to use.

Thanks


Discussion:

Resolving patch:
diff --git a/localstack/config.py b/localstack/config.py
--- a/localstack/config.py
+++ b/localstack/config.py
@@ -9,6 +9,7 @@
 from boto3 import Session
 from localstack.constants import DEFAULT_SERVICE_PORTS, LOCALHOST, PATH_USER_REQUEST, DEFAULT_PORT_WEB_UI
 
+
 # randomly inject faults to Kinesis
 KINESIS_ERROR_PROBABILITY = float(os.environ.get('KINESIS_ERROR_PROBABILITY', '').strip() or 0.0)
 
diff --git a/localstack/plugins.py b/localstack/plugins.py
--- a/localstack/plugins.py
+++ b/localstack/plugins.py
@@ -2,7 +2,7 @@
     start_s3, start_sns, start_ses, start_apigateway,
     start_elasticsearch_service, start_lambda, start_redshift, start_firehose,
     start_cloudwatch, start_cloudformation, start_dynamodbstreams, start_route53,
-    start_ssm, start_secretsmanager)
+    start_ssm, start_sts, start_secretsmanager)
 from localstack.services.apigateway import apigateway_listener
 from localstack.services.cloudformation import cloudformation_listener
 from localstack.services.dynamodb import dynamodb_listener, dynamodb_starter
@@ -36,6 +36,8 @@ def register_localstack_plugins():
             start=start_ses))
         register_plugin(Plugin('ssm',
             start=start_ssm))
+        register_plugin(Plugin('sts',
+            start=start_sts))
         register_plugin(Plugin('secretsmanager',
             start=start_secretsmanager))
         register_plugin(Plugin('apigateway',
diff --git a/localstack/services/infra.py b/localstack/services/infra.py
--- a/localstack/services/infra.py
+++ b/localstack/services/infra.py
@@ -17,7 +17,7 @@
 from localstack.config import (USE_SSL, PORT_ROUTE53, PORT_S3,
     PORT_FIREHOSE, PORT_LAMBDA, PORT_SNS, PORT_REDSHIFT, PORT_CLOUDWATCH,
     PORT_DYNAMODBSTREAMS, PORT_SES, PORT_ES, PORT_CLOUDFORMATION, PORT_APIGATEWAY,
-    PORT_SSM, PORT_SECRETSMANAGER)
+    PORT_SSM, PORT_SECRETSMANAGER, PORT_STS)
 from localstack.utils import common, persistence
 from localstack.utils.common import (run, TMP_THREADS, in_ci, run_cmd_safe,
     TIMESTAMP_FORMAT, FuncThread, ShellCommandThread, mkdir)
@@ -162,6 +162,10 @@ def start_cloudwatch(port=PORT_CLOUDWATCH, asynchronous=False):
     return start_moto_server('cloudwatch', port, name='CloudWatch', asynchronous=asynchronous)
 
 
+def start_sts(port=PORT_STS, asynchronous=False):
+    return start_moto_server('sts', port, name='STS', asynchronous=asynchronous)
+
+
 def start_redshift(port=PORT_REDSHIFT, asynchronous=False):
     return start_moto_server('redshift', port, name='Redshift', asynchronous=asynchronous)
 


Test patch:
Repository: localstack/localstack

Issue:
Consider adding a prefix to docker environment variables
Hi,

Since environment variables are global, I think they should be prefixed by `LOCALSTACK_` in the docker image. For example `SERVICES` environment variable might conflict at some point with something else, so naming it `LOCALSTACK_SERVICES` would be nicer.

This could be optional to avoid breaking changes. Localstack would look for `LOCALSTACK_SERVICES` first, and if it's not defined would fallback to `SERVICES` just as today.

As far as I know, most (maybe all) official docker images do this. I think it's a good practice. See:
- https://hub.docker.com/_/postgres
- https://hub.docker.com/_/nginx
- https://hub.docker.com/_/mysql

Thanks.


Discussion:
Thanks @gilbsgilbs , sounds like a great idea. Do you think you could create a pull request with this change? That would be very much appreciated. I'd be happy to help out or provide guidance, if needed. Thanks!
Hi @whummer. Thanks for assigning me the issue. I'll have a look at it ASAP. 

Resolving patch:
diff --git a/localstack/config.py b/localstack/config.py
--- a/localstack/config.py
+++ b/localstack/config.py
@@ -74,13 +74,17 @@
 CONFIG_ENV_VARS = ['SERVICES', 'HOSTNAME', 'HOSTNAME_EXTERNAL', 'LOCALSTACK_HOSTNAME',
     'LAMBDA_EXECUTOR', 'LAMBDA_REMOTE_DOCKER', 'LAMBDA_DOCKER_NETWORK', 'USE_SSL', 'LICENSE_KEY', 'DEBUG',
     'KINESIS_ERROR_PROBABILITY', 'DYNAMODB_ERROR_PROBABILITY', 'PORT_WEB_UI', 'START_WEB']
+
+
 for key, value in iteritems(DEFAULT_SERVICE_PORTS):
-    backend_override_var = '%s_BACKEND' % key.upper().replace('-', '_')
-    if os.environ.get(backend_override_var):
-        CONFIG_ENV_VARS.append(backend_override_var)
-    port_external_override_var = '%s_PORT_EXTERNAL' % key.upper().replace('-', '_')
-    if os.environ.get(port_external_override_var):
-        CONFIG_ENV_VARS.append(port_external_override_var)
+    clean_key = key.upper().replace('-', '_')
+    CONFIG_ENV_VARS += [
+        clean_key + '_BACKEND',
+        clean_key + '_PORT_EXTERNAL',
+    ]
+
+
+CONFIG_ENV_VARS += ['LOCALSTACK_' + v for v in CONFIG_ENV_VARS]
 
 
 def in_docker():


Test patch:
Repository: localstack/localstack

Issue:
Support for EC2 instances 
Does Local stock support EC2 instances ,I didn't see anything mentioned about EC2 api in the cloud api section??


Discussion:
There's this, which I maintain: https://www.npmjs.com/package/aws-mock  It would be cool to have a bridge or something similar between `localstack` and `aws-mock`, so that using both would be relatively seamless to the end user.

`aws-mock` started out as being open supporting all aws services, but we only ever needed ec2.  `aws-mock` is still open to adding any other aws service, but that would be a lot of duplication that we would not want to do of what has already been done by projects such as `localstack`. 

Resolving patch:
diff --git a/localstack/constants.py b/localstack/constants.py
--- a/localstack/constants.py
+++ b/localstack/constants.py
@@ -2,7 +2,7 @@
 import localstack_client.config
 
 # LocalStack version
-VERSION = '0.9.4'
+VERSION = '0.9.5'
 
 # default AWS region
 if 'DEFAULT_REGION' not in os.environ:
diff --git a/localstack/plugins.py b/localstack/plugins.py
--- a/localstack/plugins.py
+++ b/localstack/plugins.py
@@ -7,7 +7,7 @@
 from localstack.services.infra import (register_plugin, Plugin,
     start_sns, start_ses, start_apigateway, start_elasticsearch_service, start_lambda,
     start_redshift, start_firehose, start_cloudwatch, start_dynamodbstreams, start_route53,
-    start_ssm, start_sts, start_secretsmanager, start_iam, start_cloudwatch_logs)
+    start_ssm, start_sts, start_secretsmanager, start_iam, start_cloudwatch_logs, start_ec2)
 from localstack.services.kinesis import kinesis_listener, kinesis_starter
 from localstack.services.dynamodb import dynamodb_listener, dynamodb_starter
 from localstack.services.apigateway import apigateway_listener
@@ -76,6 +76,8 @@ def register_localstack_plugins():
         register_plugin(Plugin('stepfunctions',
             start=stepfunctions_starter.start_stepfunctions,
             listener=stepfunctions_listener.UPDATE_STEPFUNCTIONS))
+        register_plugin(Plugin('ec2',
+            start=start_ec2))
     except Exception as e:
         print('Unable to register plugins: %s' % e)
         sys.stdout.flush()
diff --git a/localstack/services/infra.py b/localstack/services/infra.py
--- a/localstack/services/infra.py
+++ b/localstack/services/infra.py
@@ -262,6 +262,11 @@ def start_secretsmanager(port=None, asynchronous=False):
     return start_moto_server('secretsmanager', port, name='Secrets Manager', asynchronous=asynchronous)
 
 
+def start_ec2(port=None, asynchronous=False):
+    port = port or config.PORT_EC2
+    return start_moto_server('ec2', port, name='EC2', asynchronous=asynchronous)
+
+
 # ---------------
 # HELPER METHODS
 # ---------------


Test patch:
Repository: localstack/localstack

Issue:
Kinesis proxy hangs once ShardLimit is hit
I have tests that generate unique dynamodb tables (with streams enabled) for each test (to provide isolation) and keep running into Math.random() with tests timing out. After bash'ing into the docker container and force killing various services, I narrowed it down to kinesalite.

An easy way to reproduce isrun it within sharedLimit = 1 like so:
`node /opt/code/localstack/localstack/node_modules/kinesalite/cli.js --shardLimit 1 --port 4565`

Doing so causes dynamodb.createTable commands to hang after a few tries.


Discussion:

Resolving patch:
diff --git a/localstack/config.py b/localstack/config.py
--- a/localstack/config.py
+++ b/localstack/config.py
@@ -12,6 +12,11 @@
 
 TRUE_VALUES = ('1', 'true')
 
+# limit in which to kinesalite will start throwing exceptions
+KINESIS_SHARD_LIMIT = os.environ.get('KINESIS_SHARD_LIMIT', '').strip() or '100'
+
+# delay in kinesalite response when making changes to streams
+KINESIS_LATENCY = os.environ.get('KINESIS_LATENCY', '').strip() or '500'
 
 # randomly inject faults to Kinesis
 KINESIS_ERROR_PROBABILITY = float(os.environ.get('KINESIS_ERROR_PROBABILITY', '').strip() or 0.0)
diff --git a/localstack/services/kinesis/kinesis_starter.py b/localstack/services/kinesis/kinesis_starter.py
--- a/localstack/services/kinesis/kinesis_starter.py
+++ b/localstack/services/kinesis/kinesis_starter.py
@@ -11,17 +11,23 @@
 LOGGER = logging.getLogger(__name__)
 
 
-def start_kinesis(port=None, asynchronous=False, shard_limit=100, update_listener=None):
+def start_kinesis(port=None, asynchronous=False, update_listener=None):
     port = port or config.PORT_KINESIS
     install.install_kinesalite()
     backend_port = DEFAULT_PORT_KINESIS_BACKEND
+    latency = config.KINESIS_LATENCY
     kinesis_data_dir_param = ''
     if config.DATA_DIR:
         kinesis_data_dir = '%s/kinesis' % config.DATA_DIR
         mkdir(kinesis_data_dir)
         kinesis_data_dir_param = '--path %s' % kinesis_data_dir
-    cmd = ('%s/node_modules/kinesalite/cli.js --shardLimit %s --port %s %s' %
-        (ROOT_PATH, shard_limit, backend_port, kinesis_data_dir_param))
+    cmd = (
+        '%s/node_modules/kinesalite/cli.js --shardLimit %s --port %s'
+        ' --createStreamMs %s --deleteStreamMs %s --updateStreamMs %s %s'
+    ) % (
+        ROOT_PATH, config.KINESIS_SHARD_LIMIT, backend_port,
+        latency, latency, latency, kinesis_data_dir_param
+    )
     print('Starting mock Kinesis (%s port %s)...' % (get_service_protocol(), port))
     start_proxy_for_service('kinesis', port, backend_port, update_listener)
     return do_run(cmd, asynchronous)


Test patch:
Repository: localstack/localstack

Issue:
Fix dynamodbstreams api uuid generation incompatibility with python 3.6
#### This change set aims to fix the uuid generation error by removing `.decode('utf-8')` in python3.6.

python3.6 will return `TypeError: encoding without a string argument` when running ```uuid.uuid5(namespace=namespace, name=namestring.encode('utf-8'))``` , which seems to be only supported by python2, thus causing error on DynamoDB streams api.

Since LocalStack latest docker image runs on python3.6, I think this issue will cause shard_id generation failure in `dynamodbstreams_api.py`.

More reference regarding to this issue:
`https://bugs.python.org/issue34145` 



Discussion:
Thanks for fixing this @ilovelili . Left a minor comment, regarding use of existing utility functions. Do you think we could give that a try? Thanks

[![Coverage Status](https://coveralls.io/builds/25098824/badge)](https://coveralls.io/builds/25098824)

Coverage decreased (-0.1%) to 69.325% when pulling **1f09226eb18493580a3e848d809542ad0bd458e1 on ilovelili:master** into **4f15f86aac317a7636434455f8458d4fb86b36c4 on localstack:master**.


Resolving patch:
diff --git a/localstack/services/dynamodbstreams/dynamodbstreams_api.py b/localstack/services/dynamodbstreams/dynamodbstreams_api.py
--- a/localstack/services/dynamodbstreams/dynamodbstreams_api.py
+++ b/localstack/services/dynamodbstreams/dynamodbstreams_api.py
@@ -133,8 +133,8 @@ def stream_name_from_stream_arn(stream_arn):
 
 
 def random_id(stream_arn, kinesis_shard_id):
-    namespace = uuid.UUID(bytes=hashlib.sha1(stream_arn.encode('utf-8')).digest()[:16])
-    return uuid.uuid5(namespace, to_bytes(kinesis_shard_id)).hex
+    namespace = uuid.UUID(bytes=hashlib.sha1(to_bytes(stream_arn)).digest()[:16])
+    return uuid.uuid5(namespace, kinesis_shard_id).hex
 
 
 def shard_id(stream_arn, kinesis_shard_id):


Test patch:
Repository: localstack/localstack

Issue:
Lambda not found check broken if qualifier is provided
# Steps to reproduce

* Start `localstack` (version 0.10.3).
* Don't create any lambda functions.
* Run:

```sh
AWS_ACCESS_KEY_ID='a' AWS_SECRET_ACCESS_KEY='b' \
aws lambda invoke \
  --function-name 'my-func' \
  --qualifier='qual' \
  --endpoint http://localhost:4574 test.out
```

* Expected behaviour — a `ResourceNotFoundException` from `aws-cli`.
* Actual behaviour — `An error occurred (500) when calling the Invoke operation` message and a 500 response.

This bug only appears if a `qualifier` is included in the request.


Discussion:

Resolving patch:
diff --git a/localstack/services/awslambda/lambda_api.py b/localstack/services/awslambda/lambda_api.py
--- a/localstack/services/awslambda/lambda_api.py
+++ b/localstack/services/awslambda/lambda_api.py
@@ -942,8 +942,9 @@ def _create_response(result, status_code=200):
     not_found = None
     if arn not in arn_to_lambda:
         not_found = not_found_error(arn)
-    if qualifier and not arn_to_lambda.get(arn).qualifier_exists(qualifier):
+    elif qualifier and not arn_to_lambda.get(arn).qualifier_exists(qualifier):
         not_found = not_found_error('{0}:{1}'.format(arn, qualifier))
+
     if not_found:
         forward_result = forward_to_fallback_url(func_arn, data)
         if forward_result is not None:


Test patch: