Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ make install
make test
```

## Changelog

* v0.2: Add missing service endpoints; enable SSL connections; put default endpoints into config.py
* v0.1: Initial version

## License

The LocalStack Python Client is released under the Apache License, Version 2.0 (see `LICENSE`).
30 changes: 30 additions & 0 deletions localstack_client/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import json

_service_endpoints_template = {
'apigateway': '{proto}://{host}:4567',
'kinesis': '{proto}://{host}:4568',
'dynamodb': '{proto}://{host}:4569',
'dynamodbstreams': '{proto}://{host}:4570',
'elasticsearch': '{proto}://{host}:4571',
's3': '{proto}://{host}:4572',
'firehose': '{proto}://{host}:4573',
'lambda': '{proto}://{host}:4574',
'sns': '{proto}://{host}:4575',
'sqs': '{proto}://{host}:4576',
'redshift': '{proto}://{host}:4577',
'es': '{proto}://{host}:4578',
'ses': '{proto}://{host}:4579',
'route53': '{proto}://{host}:4580',
'cloudformation': '{proto}://{host}:4581',
'cloudwatch': '{proto}://{host}:4582'
}


def get_service_endpoints(localstack_host=None):
if localstack_host is None:
localstack_host = os.environ.get('LOCALSTACK_HOST', 'localhost')
protocol = 'https' if os.environ.get('USE_SSL') in ('1', 'true') else 'http'

return json.loads(json.dumps(_service_endpoints_template)
.replace('{proto}', protocol).replace('{host}', localstack_host))
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import boto3.session
from botocore.credentials import Credentials
from localstack_client import config

DEFAULT_SESSION = None

Expand All @@ -19,18 +20,7 @@ def __init__(self, aws_access_key_id='accesskey', aws_secret_access_key='secretk
self.aws_secret_access_key = aws_secret_access_key
self.aws_session_token = aws_session_token
self.region_name = region_name

if localstack_host is None:
localstack_host = os.environ.get('LOCALSTACK_HOST', 'localhost')

self._service_endpoint_mapping = {
'kinesis': 'http://%s:4568' % (localstack_host),
'dynamodb': 'http://%s:4569' % (localstack_host),
's3': 'http://%s:4572' % (localstack_host),
'es': 'http://%s:4578' % (localstack_host),
'firehose': 'http://%s:4573' % (localstack_host),
'sqs': 'http://%s:4576' % (localstack_host)
}
self._service_endpoint_mapping = config.get_service_endpoints(localstack_host)

def get_credentials(self):
"""
Expand All @@ -45,14 +35,14 @@ def client(self, service_name, **kwargs):
raise Exception('%s is not supported by this mock session.' % (service_name))

return boto3.client(service_name, endpoint_url=self._service_endpoint_mapping[service_name],
region_name=self.region_name)
region_name=self.region_name, verify=False)

def resource(self, service_name, **kwargs):
if service_name not in self._service_endpoint_mapping:
raise Exception('%s is not supported by this mock session.' % (service_name))
return boto3.resource(service_name,
endpoint_url=self._service_endpoint_mapping[service_name],
region_name=self.region_name)
region_name=self.region_name, verify=False)


def _get_default_session():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='localstack-client',
version='0.1',
version='0.2',
description='A lightweight python client for LocalStack.',
author='Jeff Wu, Waldemar Hummer',
author_email='jeffrey.yung.wu@gmail.com, waldemar.hummer@gmail.com',
Expand Down
4 changes: 2 additions & 2 deletions tests/client/test_python_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from localstack_client import localstack_client
import localstack_client.session


def test_session():
session = localstack_client.Session()
session = localstack_client.session.Session()
sqs = session.client('sqs')
assert sqs.list_queues() is not None