3

我在 macOS(Mojave)的 docker 中运行 localstack。我可以使用其他一些服务,如 s3、DynamoDb、SQS;但我无法使用 SSM。

我尝试使用带有命令的 aws-cli

aws --endpoint-url=http://localhost:4583 --region ap-souteast-1 ssm put-parameter --name dev-param --value df00a020-4937-47be-8ec8-e2a25f45ae2a --type String --overwrite

我得到的回应

Could not connect to the endpoint URL: "http://localhost:4583/"

我尝试使用 java sdk

public SsmService() {
        this.ssmClient = AWSSimpleSystemsManagementClientBuilder.standard()
                .withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(SSM_ENDPOINT,REGION))
                .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("key", "key")))
                .build();
    }

    public void saveParam(String paramName, String paramValue,boolean overWrite) {

        try {
            PutParameterRequest putParameterRequest = new PutParameterRequest();
            putParameterRequest.setName(paramName);
            putParameterRequest.setValue(paramValue);
            putParameterRequest.setOverwrite(overWrite);
            putParameterRequest.setType("String");

            var result = ssmClient.putParameter(putParameterRequest);
            System.out.println("result = " + result.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

new SsmService().saveParam("dev-kms-key-id","df00a020-4937-47be-8ec8-e2a25f45ae2a",true);

我又得到了错误

com.amazonaws.SdkClientException: Unable to execute HTTP request: Connect to localhost:4583 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1175)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1121)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:770)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:744)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
    at com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient.doInvoke(AWSSimpleSystemsManagementClient.java:8446)
    at com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient.invoke(AWSSimpleSystemsManagementClient.java:8413)
    at com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient.invoke(AWSSimpleSystemsManagementClient.java:8402)
    at com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient.executePutParameter(AWSSimpleSystemsManagementClient.java:6626)
    at com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClient.putParameter(AWSSimpleSystemsManagementClient.java:6598)
    at com.bkash.rnd.ssm.SsmService.saveParam(SsmService.java:38)
    at com.bkash.rnd.LocalstactAwsApplication.main(LocalstactAwsApplication.java:70)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:4583 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76)
    at com.amazonaws.http.conn.$Proxy51.connect(Unknown Source)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
    at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1297)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1113)
    ... 14 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)
    at java.base/java.net.Socket.connect(Socket.java:591)
    at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:75)
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
    ... 30 more

了解如何解决此问题并能够在localhost:4583

4

1 回答 1

1

确保在启动 localstack 时正确映射端口。例如,您可以使用-p4583:4583映射容器和主机的端口

于 2020-03-19T03:03:02.727 回答