Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何设置不需要凭据的Localstack容器?_Java_Amazon Web Services_Testcontainers_Aws Secrets Manager_Localstack - Fatal编程技术网

Java 如何设置不需要凭据的Localstack容器?

Java 如何设置不需要凭据的Localstack容器?,java,amazon-web-services,testcontainers,aws-secrets-manager,localstack,Java,Amazon Web Services,Testcontainers,Aws Secrets Manager,Localstack,我有以下代码片段,应该在AWS Lambda函数中运行: AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard().withRegion(AWS_REGION).build(); GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest().withSecretId(SECRET_NAME); GetSecretValueResul

我有以下代码片段,应该在AWS Lambda函数中运行:

AWSSecretsManager client = AWSSecretsManagerClientBuilder.standard().withRegion(AWS_REGION).build();
GetSecretValueRequest getSecretValueRequest = new GetSecretValueRequest().withSecretId(SECRET_NAME);
GetSecretValueResult secretValue = client.getSecretValue(getSecretValueRequest);
由于lambda功能将在与secret manager相同的VPC中运行,因此我不必为其提供凭据(
AWS\u ACCESS\u KEY\u ID
AWS\u secret\u ACCESS\u KEY

我使用Localstack和Testcontainers进行集成测试,并在测试设置中设置了如下秘密:

AWSSecretsManager secretsManager = AWSSecretsManagerClientBuilder.standard()
        .withEndpointConfiguration(secretsmanager.getEndpointConfiguration(SECRETSMANAGER))
        .withCredentials(secretsmanager.getDefaultCredentialsProvider())
        .build();
String secretString = "{'engine':'mysql','port':" + mysql.getMappedPort(3306) + ",'host':'" + mysql.getContainerIpAddress() + "'}";
CreateSecretRequest request = new CreateSecretRequest().withName("aurora")
        .withSecretString(secretString)
        .withRequestCredentialsProvider(secretsmanager.getDefaultCredentialsProvider());
secretsManager.createSecret(request);
现在,测试崩溃并出现错误:

com.amazonaws.services.secretsmanager.model.AWSSecretsManagerException: 
The security token included in the request is invalid. 
(Service: AWSSecretsManager; 
Status Code: 400; Error Code: 
UnrecognizedClientException; 
Request ID: ...
以下是测试中使用的localstack容器的定义:

@ClassRule
public static LocalStackContainer secretsmanager = new LocalStackContainer("0.10.4")
    .withServices(LocalStackContainer.Service.SECRETSMANAGER)
    .withEnv("DEFAULT_REGION", "eu-west-1")
    .withExposedPorts(4584);

如何将LocalStackContainer配置为在不进行任何凭据验证的情况下接受请求?

“如何将LocalStackContainer配置为在不进行任何凭据验证的情况下接受请求?”-我认为您不能,因为您试图向aws secretsmanager发出请求,而该管理员需要有效的awscredentials@Ira嗯,我也面临同样的问题。你找到解决办法了吗?我不记得错误是怎么解决的。现在我可以看到我的LocalStackContainer还有另外两个环境变量:。withEnv(“主机名”),withEnv(“LOCALSTACK_主机名”),但我不确定这是否是我缺少的。感谢您的快速回复。我已经试过了,但还是犯了同样的错误。请看一看。@Ira Re而不是secretsmanager.eu-west-1.amazonaws.com我使用localhost.–未知2小时前删除