【问题标题】:Spring AWS Context Credentials - Not WorkingSpring AWS 上下文凭证 - 不工作
【发布时间】:2018-01-03 19:16:57
【问题描述】:

我遇到了与提到的here 类似的问题。我正在使用 spring xml 配置。我指定了我的全局 AWS 上下文凭证。我正在使用 S3 出站通道适配器从 S3 下载文件。我在 config.properties 文件中指定了我的密钥。我仍然看不到用于与 S3 对话的凭据。

s3-read.xml

<int-aws:s3-outbound-channel-adapter  
               transfer-manager="transferManager"
               bucket-expression="'${s3.bucket}'"
               command-expression="'DOWNLOAD'"
               key-expression="headers.S3Key"
               progress-listener="progressListener" /> 

aws-credentials.xml

<aws-context:context-credentials>
<aws-context:simple-credentials access-key="${aws.accesskey}"
                                secret-key="${aws.secretkey}"/>
</aws-context:context-credentials> 

<!-- Define global region -->
<aws-context:context-region region="${aws.region}"/> 

config.properties

aws.accesskey=accesskey
aws.secretkey=secretkey
aws.region=us-west-2

例外是:

com.amazonaws.SdkClientException: Unable to load AWS credentials from any 
provider in the chain

我在这方面花了很多时间。当我尝试调试时,它似乎在寻找默认凭据提供程序链,它正在寻找环境变量或 ~/.aws/credentials 文件。我没有指定任何内容。

如何链接 S3 以使用这些凭据?感谢您的帮助。

【问题讨论】:

    标签: java spring spring-integration-aws


    【解决方案1】:

    在我的项目中,我使用了这样的“BasicAWSCredentials”

    public S3StorageService(AmazonS3Config s3Configs) {
        ClientConfiguration opts = new ClientConfiguration();
        opts.setSignerOverride("S3SignerType");
        BasicAWSCredentials credentials = new BasicAWSCredentials(s3Configs.getAccessKey(), s3Configs.getSecretKey());
        AmazonS3 amazonS3 = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withEndpointConfiguration(new EndpointConfiguration(s3Configs.getServiceEndpoint(), ""))
                .withClientConfiguration(opts).build();
        String defaultBucket = s3Configs.getDefaultBucket();
    
    }
    
    @ConfigurationProperties(prefix = "ds31s3.amazon")
    public class AmazonS3Config {   
        private String  accessKey;
        private String  secretKey;
        private String  serviceEndpoint;    
        private String  defaultBucket;
    

    在 application.properties 中

    #Amazon S3 Configs
    ds31s3.amazon.accessKey=<KEY>
    ds31s3.amazon.secretKey=<SECRETKEY>
    ds31s3.amazon.serviceEndpoint=<ENDPOINT>
    ds31s3.amazon.defaultBucket=bucket-karthik
    

    而且效果很好。

    【讨论】:

    • 是的,通过 Java 代码就可以了。我正在寻找使用xml配置的方式。
    猜你喜欢
    • 2020-02-26
    • 2017-06-20
    • 2014-03-30
    • 2017-11-16
    • 2017-05-04
    • 2021-03-08
    • 2020-10-14
    • 1970-01-01
    • 2018-04-08
    相关资源
    最近更新 更多