Search code examples
springamazon-web-servicesspring-bootspring-cloudspring-messaging

Spring cloud aws dependency effect on property injection


I want to connect AWS with using spring cloud.

This is a piece of myconfig class :

@EnableSqs
public class AwsCloudConfig {

    @Value("${cloud.aws.region}")
    private String region;

    @Value("${cloud.aws.profile}")
    private String profile;

    @Value("${cloud.aws.roleArn}")
    private String role;

    @Value("${cloud.aws.user}")
    private String userKey;

    @Value("${cloud.aws.credentials.accessKey}")
    private String accessKey;

    @Value("${cloud.aws.credentials.secretKey}")
    private String secretKey;

    //... 

}

Normally Spring inject these properties from my properties file without any problem.

But it doesn't inject them whem I add this dependency :

org.springframework.cloud:spring-cloud-starter-aws-messaging

Why this dependency effects springs property injection functionality? is there any idea?


Solution

  • can you try like this ?

     @Bean
    public AmazonS3 amazonS3(@Value("${cloud.aws.credentials.accessKey}") String accessKey,
                             @Value("${cloud.aws.credentials.secretKey}") String secretKey,
                             @Value("${cloud.aws.region}") String region) {
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        AmazonS3 amazonS3ClientBuilder= AmazonS3ClientBuilder.standard()
                .withRegion(region)
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .build();
        return amazonS3ClientBuilder;
    }