2

我在 docker 容器中安装了 localstack 和 awscli。我运行不同的 aws 命令来列出流和存储桶,但是当我尝试列出 dynamoDB 表时(如下所示),它失败了:

aws --region us-east-1 --endpoint-url=http://localhost:4569 dynamodb list-tables

这是我得到的错误:

2018-07-12T09:26:35:ERROR:localstack.services.generic_proxy: Error forwarding request: HTTPConnectionPool(host='127.0.0.1', port=4564): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f68941a43d0>: Failed to establish a new connection: [Errno 111] Connection refused',)) Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/localstack/services/generic_proxy.py", line 201, in forward
    headers=forward_headers)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 508,in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 618,in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 508,in send
    raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=4564): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f68941a43d0>: Failed to establish a new connection: [Errno 111] Connection refused',))

我没有在互联网上找到任何解决我问题的回复。

如果有人有线索或想法,我将不胜感激。

提前致谢

4

2 回答 2

2

如果您想在 localstack 上查看您的 Dynamo DB,您可以安装 Commandeer,它为您提供本地和 AWS 的 UI。 https://getcommandeer.com

于 2019-09-05T21:37:13.200 回答
1

如果您使用的是 Java,您可以使用该jar库来模拟一些亚马逊组件:

首先,您需要在测试中添加以下组件,pom.xml以便能够在测试期间直接初始化本地堆栈:

<dependency>
    <groupId>cloud.localstack</groupId>
    <artifactId>localstack-utils</artifactId>
    <version>0.2.0</version>
    <scope>test</scope>
</dependency>

然后,如果您需要使用 dynamo,则需要指定以下库,因为aws提供的最新版本与最新版本的 localstack 不兼容:

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-core</artifactId>
    <version>1.11.721</version>
    <scope>test</scope>
</dependency>

现在您可以使用以下注释来使用 docker 实例化堆栈,如果系统中不存在图像,则会自动拉取图像。所以 no 没有必要运行任何 docker/docker-compose 图像。

@LocalstackDockerProperties(services = {"dynamodb"})
@ExtendWith(LocalstackDockerExtension.class)
@Slf4j
public class TestPipelineComplete {

public static final String AWS_ACCESS_KEY_ID = "foo";
public static final String AWS_SECRET_ACCESS_KEY = "bar";
    static {
        System.setProperty("AWS_ACCESS_KEY_ID", AWS_ACCESS_KEY_ID);
        System.setProperty("AWS_SECRET_ACCESS_KEY", AWS_SECRET_ACCESS_KEY);
    }
}

现在,如果您需要初始化DynamoDB客户端,可以使用以下行:

final AmazonDynamoDB clientDynamoDB = cloud.localstack.TestUtils.getClientDynamoDB();
于 2020-02-12T15:39:27.650 回答