Unable to load AWS credentials from any provider in the chain - profile file cannot be null












1














I'm trying to use AmazonSNS in my Spring Boot application and I'm able to use it locally, but as soon as I'm deploying it on my development server, I'm getting this error:



Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@46a123e4: The requested metadata is not found at http://169.254.169.254/latest/meta-data/iam/security-credentials/ , com.amazonaws.auth.profile.ProfileCredentialsProvider@44bc2449: profile file cannot be null]


If I don't get it wrong, my server is not able to get any AWS credentials. I don't understand why, because AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set as environment variables. My code looks like that:



private AmazonSNS amazonSNS;

@Autowired
public AmazonSNSPublisherService() {
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).withRegion("eu-west-1").build();
}


I tried this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withRegion("eu-west-1").build();


And this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(new EnvironmentVariableCredentialsProvider()).withRegion("eu-west-1").build();


But I'm always getting the same error.










share|improve this question






















  • can you confirm AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY exists in your env?
    – slimane
    Nov 22 at 18:37










  • @slimane When I look the "environment" tab in my pod (in the OpenShift web console), both variables are present.
    – VincentS
    Nov 22 at 19:13










  • I had a look at docs, I thing DEBUG will show more informations about the error, can you enable it and post the logs?
    – slimane
    Nov 22 at 19:20












  • Thanks @slimane, you put me on the right track to find the solution (see above).
    – VincentS
    Nov 26 at 8:31
















1














I'm trying to use AmazonSNS in my Spring Boot application and I'm able to use it locally, but as soon as I'm deploying it on my development server, I'm getting this error:



Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@46a123e4: The requested metadata is not found at http://169.254.169.254/latest/meta-data/iam/security-credentials/ , com.amazonaws.auth.profile.ProfileCredentialsProvider@44bc2449: profile file cannot be null]


If I don't get it wrong, my server is not able to get any AWS credentials. I don't understand why, because AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set as environment variables. My code looks like that:



private AmazonSNS amazonSNS;

@Autowired
public AmazonSNSPublisherService() {
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).withRegion("eu-west-1").build();
}


I tried this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withRegion("eu-west-1").build();


And this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(new EnvironmentVariableCredentialsProvider()).withRegion("eu-west-1").build();


But I'm always getting the same error.










share|improve this question






















  • can you confirm AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY exists in your env?
    – slimane
    Nov 22 at 18:37










  • @slimane When I look the "environment" tab in my pod (in the OpenShift web console), both variables are present.
    – VincentS
    Nov 22 at 19:13










  • I had a look at docs, I thing DEBUG will show more informations about the error, can you enable it and post the logs?
    – slimane
    Nov 22 at 19:20












  • Thanks @slimane, you put me on the right track to find the solution (see above).
    – VincentS
    Nov 26 at 8:31














1












1








1







I'm trying to use AmazonSNS in my Spring Boot application and I'm able to use it locally, but as soon as I'm deploying it on my development server, I'm getting this error:



Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@46a123e4: The requested metadata is not found at http://169.254.169.254/latest/meta-data/iam/security-credentials/ , com.amazonaws.auth.profile.ProfileCredentialsProvider@44bc2449: profile file cannot be null]


If I don't get it wrong, my server is not able to get any AWS credentials. I don't understand why, because AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set as environment variables. My code looks like that:



private AmazonSNS amazonSNS;

@Autowired
public AmazonSNSPublisherService() {
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).withRegion("eu-west-1").build();
}


I tried this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withRegion("eu-west-1").build();


And this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(new EnvironmentVariableCredentialsProvider()).withRegion("eu-west-1").build();


But I'm always getting the same error.










share|improve this question













I'm trying to use AmazonSNS in my Spring Boot application and I'm able to use it locally, but as soon as I'm deploying it on my development server, I'm getting this error:



Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@46a123e4: The requested metadata is not found at http://169.254.169.254/latest/meta-data/iam/security-credentials/ , com.amazonaws.auth.profile.ProfileCredentialsProvider@44bc2449: profile file cannot be null]


If I don't get it wrong, my server is not able to get any AWS credentials. I don't understand why, because AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are set as environment variables. My code looks like that:



private AmazonSNS amazonSNS;

@Autowired
public AmazonSNSPublisherService() {
this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).withRegion("eu-west-1").build();
}


I tried this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withRegion("eu-west-1").build();


And this:



this.amazonSNS = AmazonSNSClientBuilder.standard().withCredentials(new EnvironmentVariableCredentialsProvider()).withRegion("eu-west-1").build();


But I'm always getting the same error.







spring spring-boot amazon-sns






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 at 18:26









VincentS

335516




335516












  • can you confirm AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY exists in your env?
    – slimane
    Nov 22 at 18:37










  • @slimane When I look the "environment" tab in my pod (in the OpenShift web console), both variables are present.
    – VincentS
    Nov 22 at 19:13










  • I had a look at docs, I thing DEBUG will show more informations about the error, can you enable it and post the logs?
    – slimane
    Nov 22 at 19:20












  • Thanks @slimane, you put me on the right track to find the solution (see above).
    – VincentS
    Nov 26 at 8:31


















  • can you confirm AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY exists in your env?
    – slimane
    Nov 22 at 18:37










  • @slimane When I look the "environment" tab in my pod (in the OpenShift web console), both variables are present.
    – VincentS
    Nov 22 at 19:13










  • I had a look at docs, I thing DEBUG will show more informations about the error, can you enable it and post the logs?
    – slimane
    Nov 22 at 19:20












  • Thanks @slimane, you put me on the right track to find the solution (see above).
    – VincentS
    Nov 26 at 8:31
















can you confirm AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY exists in your env?
– slimane
Nov 22 at 18:37




can you confirm AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY exists in your env?
– slimane
Nov 22 at 18:37












@slimane When I look the "environment" tab in my pod (in the OpenShift web console), both variables are present.
– VincentS
Nov 22 at 19:13




@slimane When I look the "environment" tab in my pod (in the OpenShift web console), both variables are present.
– VincentS
Nov 22 at 19:13












I had a look at docs, I thing DEBUG will show more informations about the error, can you enable it and post the logs?
– slimane
Nov 22 at 19:20






I had a look at docs, I thing DEBUG will show more informations about the error, can you enable it and post the logs?
– slimane
Nov 22 at 19:20














Thanks @slimane, you put me on the right track to find the solution (see above).
– VincentS
Nov 26 at 8:31




Thanks @slimane, you put me on the right track to find the solution (see above).
– VincentS
Nov 26 at 8:31












2 Answers
2






active

oldest

votes


















2














I cannot explain why, but my problem was this dependency in my pom file:



<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>


As soon as I removed it, the DefaultAWSCredentialsProviderChain worked perfectly.






share|improve this answer





























    0














    It's difficult to diagnose your specific problem, but I had the same issue, also in a Spring Boot application. The reason was because Spring Boot (potentially the spring-cloud-starter-aws package) creates its own Credentials Provider Chain and where I had placed



    @Autowired
    private AmazonS3 s3Client;


    Was injected into the Spring bean container BEFORE my @Bean method was executed:



    @Bean
    @Primary
    public AWSCredentialsProvider buildDefaultAWSCredentialsProvider() {
    return new DefaultAWSCredentialsProviderChain();
    }


    In fact, I put both snippets in the same @Configuration class and I didn't realize the @Autowired bean was injected from the Spring container (which starts out with AmazonS3 client and DefaultAWSCredentialsProviderChain credential created by Spring Boot) before my @Bean was instantiated and inserted into the Spring container.



    Anyways, try looking to see if you're @Autowired injecting the credentials OR a client that uses it in a place that gets executed before YOUR credentials and YOUR SNS client.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436450%2funable-to-load-aws-credentials-from-any-provider-in-the-chain-profile-file-can%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      I cannot explain why, but my problem was this dependency in my pom file:



      <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-aws</artifactId>
      </dependency>


      As soon as I removed it, the DefaultAWSCredentialsProviderChain worked perfectly.






      share|improve this answer


























        2














        I cannot explain why, but my problem was this dependency in my pom file:



        <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-aws</artifactId>
        </dependency>


        As soon as I removed it, the DefaultAWSCredentialsProviderChain worked perfectly.






        share|improve this answer
























          2












          2








          2






          I cannot explain why, but my problem was this dependency in my pom file:



          <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-aws</artifactId>
          </dependency>


          As soon as I removed it, the DefaultAWSCredentialsProviderChain worked perfectly.






          share|improve this answer












          I cannot explain why, but my problem was this dependency in my pom file:



          <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-aws</artifactId>
          </dependency>


          As soon as I removed it, the DefaultAWSCredentialsProviderChain worked perfectly.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 at 8:36









          VincentS

          335516




          335516

























              0














              It's difficult to diagnose your specific problem, but I had the same issue, also in a Spring Boot application. The reason was because Spring Boot (potentially the spring-cloud-starter-aws package) creates its own Credentials Provider Chain and where I had placed



              @Autowired
              private AmazonS3 s3Client;


              Was injected into the Spring bean container BEFORE my @Bean method was executed:



              @Bean
              @Primary
              public AWSCredentialsProvider buildDefaultAWSCredentialsProvider() {
              return new DefaultAWSCredentialsProviderChain();
              }


              In fact, I put both snippets in the same @Configuration class and I didn't realize the @Autowired bean was injected from the Spring container (which starts out with AmazonS3 client and DefaultAWSCredentialsProviderChain credential created by Spring Boot) before my @Bean was instantiated and inserted into the Spring container.



              Anyways, try looking to see if you're @Autowired injecting the credentials OR a client that uses it in a place that gets executed before YOUR credentials and YOUR SNS client.






              share|improve this answer


























                0














                It's difficult to diagnose your specific problem, but I had the same issue, also in a Spring Boot application. The reason was because Spring Boot (potentially the spring-cloud-starter-aws package) creates its own Credentials Provider Chain and where I had placed



                @Autowired
                private AmazonS3 s3Client;


                Was injected into the Spring bean container BEFORE my @Bean method was executed:



                @Bean
                @Primary
                public AWSCredentialsProvider buildDefaultAWSCredentialsProvider() {
                return new DefaultAWSCredentialsProviderChain();
                }


                In fact, I put both snippets in the same @Configuration class and I didn't realize the @Autowired bean was injected from the Spring container (which starts out with AmazonS3 client and DefaultAWSCredentialsProviderChain credential created by Spring Boot) before my @Bean was instantiated and inserted into the Spring container.



                Anyways, try looking to see if you're @Autowired injecting the credentials OR a client that uses it in a place that gets executed before YOUR credentials and YOUR SNS client.






                share|improve this answer
























                  0












                  0








                  0






                  It's difficult to diagnose your specific problem, but I had the same issue, also in a Spring Boot application. The reason was because Spring Boot (potentially the spring-cloud-starter-aws package) creates its own Credentials Provider Chain and where I had placed



                  @Autowired
                  private AmazonS3 s3Client;


                  Was injected into the Spring bean container BEFORE my @Bean method was executed:



                  @Bean
                  @Primary
                  public AWSCredentialsProvider buildDefaultAWSCredentialsProvider() {
                  return new DefaultAWSCredentialsProviderChain();
                  }


                  In fact, I put both snippets in the same @Configuration class and I didn't realize the @Autowired bean was injected from the Spring container (which starts out with AmazonS3 client and DefaultAWSCredentialsProviderChain credential created by Spring Boot) before my @Bean was instantiated and inserted into the Spring container.



                  Anyways, try looking to see if you're @Autowired injecting the credentials OR a client that uses it in a place that gets executed before YOUR credentials and YOUR SNS client.






                  share|improve this answer












                  It's difficult to diagnose your specific problem, but I had the same issue, also in a Spring Boot application. The reason was because Spring Boot (potentially the spring-cloud-starter-aws package) creates its own Credentials Provider Chain and where I had placed



                  @Autowired
                  private AmazonS3 s3Client;


                  Was injected into the Spring bean container BEFORE my @Bean method was executed:



                  @Bean
                  @Primary
                  public AWSCredentialsProvider buildDefaultAWSCredentialsProvider() {
                  return new DefaultAWSCredentialsProviderChain();
                  }


                  In fact, I put both snippets in the same @Configuration class and I didn't realize the @Autowired bean was injected from the Spring container (which starts out with AmazonS3 client and DefaultAWSCredentialsProviderChain credential created by Spring Boot) before my @Bean was instantiated and inserted into the Spring container.



                  Anyways, try looking to see if you're @Autowired injecting the credentials OR a client that uses it in a place that gets executed before YOUR credentials and YOUR SNS client.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 21 at 17:41









                  Brooks

                  3,18622454




                  3,18622454






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53436450%2funable-to-load-aws-credentials-from-any-provider-in-the-chain-profile-file-can%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Berounka

                      Sphinx de Gizeh

                      Different font size/position of beamer's navigation symbols template's content depending on regular/plain...