FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
testcontainers-python/testcontainers/localstack.py at master · orsolli/testcontainers-python · GitHub
orsolli
/
testcontainers-python
Public
forked from
testcontainers/testcontainers-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
testcontainers-python
/
testcontainers
/
localstack.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (52 loc) · 2.2 KB
Breadcrumbs
testcontainers-python
/
testcontainers
/
localstack.py
Copy path
File metadata and controls
59 lines (52 loc) · 2.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from
testcontainers
.
core
.
waiting_utils
import
wait_for_logs
from
testcontainers
.
core
.
container
import
DockerContainer
class
LocalStackContainer
(
DockerContainer
):
"""
Localstack container.
Example
-------
::
localstack = LocalStackContainer(image="localstack/localstack:0.11.4")
localstack.with_services("dynamodb", "lambda")
localstack.start()
dynamo_endpoint = localstack.get_url()
dynamo_client = boto3.client("dynamodb", endpoint_url=dynamo_endpoint)
scan_result = dynamo_client.scan(TableName='foo')
# Do something with the scan result
"""
EDGE_PORT
=
4566
IMAGE
=
'localstack/localstack:0.11.4'
def
__init__
(
self
,
image
=
IMAGE
):
super
(
LocalStackContainer
,
self
).
__init__
(
image
)
self
.
with_exposed_ports
(
LocalStackContainer
.
EDGE_PORT
)
def
with_services
(
self
,
*
services
):
"""
Restrict what services to run. By default all localstack services are launched.
:return: the DockerContainer to allow chaining of 'with_*' calls.
"""
return
self
.
with_env
(
'SERVICES'
,
','
.
join
(
services
))
def
get_url
(
self
):
"""
Use this to call localstack instead of real AWS services.
ex: boto3.client('lambda', endpoint_url=localstack.get_url())
:return: the endpoint where localstack is reachable.
"""
host
=
self
.
get_container_host_ip
()
port
=
self
.
get_exposed_port
(
LocalStackContainer
.
EDGE_PORT
)
return
'http://{}:{}'
.
format
(
host
,
port
)
def
start
(
self
,
timeout
=
60
):
super
().
start
()
wait_for_logs
(
self
,
r'Ready\.\n'
,
timeout
=
timeout
)
return
self
Back
|
FazBrowse Home
|
New Git URL