DynamoDB Authentication With AWS SDK for Java



我使用AWS SDK for Java,我需要通过ARN用户/角色在数据库中进行身份验证。我该怎么做呢?实际上,我使用accessKey和secretKey进行身份验证,但我需要更改(组织规则)以使用ARN。

实际上通过这个验证:

@Configuration
@EnableDynamoDBRepositories(basePackages = "mypackage.repository")
public class DynamoDBConfiguration {
@Bean
public AmazonDynamoDB amazonDynamoDB(AWSCredentials AWSCredentials,
@Value("${aws.dynamoDBUrl}") String dynamoDBUrl){
AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(dynamoDBUrl, "sa-east-1"))
.withCredentials(new AWSStaticCredentialsProvider(AWSCredentials));
AmazonDynamoDB build = builder.build();
return build;
}
@Bean
public AWSCredentials awsCredentials(@Value("${aws.accessKey}") String accessKey,
@Value("${aws.secretKey}") String secretKey){
return new BasicAWSCredentials(accessKey, secretKey);
}
}

连接的API不支持用户名,两个键都需要。

通常,当我开发时,我设置凭据和配置来执行我需要的身份验证。这样我就不用在代码中传递它们了。然后,当您的代码在AWS计算资源上运行时,您可以为计算实例指定角色(示例包括:EC2、Fargate Container和Lambda)。然后这个角色可以被授予您需要的权限。

这个概念通常更安全,因为您不需要在应用程序中管理任何凭据。

我唯一一次处理本地凭证是在我开发安装在台式计算机上的东西时。在这些情况下,我使用SSO API来获取密钥和会话令牌。

最新更新