关于 java:Unable to load AWS credentials from any provider in the chain in Docker EC2 env

Unable to load AWS credentials from any provider in the chain in Docker EC2 env

我已经对一个使用 Amazon SQS 的 Java spring-boot(v1.4.2) 应用程序进行了 docker 化(通过 spring-cloud-starter-aws-messaging v1.1.3 引入了 aws-java-sdk-sqs v1.11.18)。现在要提供对 AWS 的应用程序访问,我遵循以下模式:

1
2
3
4
5
6
7
8
    @Bean
    public AmazonSQSAsync amazonSQSAsync() {
        AWSCredentials credentials = new BasicAWSCredentials(sourceSqsAccessKey, sourceSqsSecretKey);
        AmazonSQSAsyncClient sqs = new AmazonSQSAsyncClient(credentials);
        sqs.setRegion(Region.getRegion(Regions.fromName(sourceSqsRegion)));

        return new AmazonSQSBufferedAsyncClient(sqs);
    } // WHICH GETS IT CREDS FROM A .yml PROPERTIES FILE

这通常可以让我绕过异常:com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain 在本地运行和部署到我的服务器时。

我的问题是:当我将此服务部署到我的服务器时,我收到异常 Caused by: com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain 这不会在本地发生,也不会发生在我部署到该环境的任何其他服务上。没有人将凭据作为环境或系统变量或类似的东西传递。唯一的区别是这个服务使用 spring-cloud-starter-aws-messaging 而其他服务直接获取 sqs 依赖。

在将 –env-add AWS_ACCESS_KEY_ID=some_access –env-add AWS_SECRET_ACCESS_KEY=some_secret 作为环境变量提供给 docker 时,我也会收到此错误。

编辑见下面的日志:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
20170218 08:47:10.408  WARN [application name used to be here…,,,] 1 [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ’embeddedServletContainerCustomizerBeanPostProcessor’: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cache.annotation.ProxyCachingConfiguration’: Unsatisfied dependency expressed through method ‘setConfigurers’ parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cloud.aws.cache.config.annotation.ElastiCacheCachingConfiguration’: Unsatisfied dependency expressed through field ‘stackResourceFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘stackResourceRegistryFactoryBean’ defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration$StackAutoDetectConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method ‘stackResourceRegistryFactoryBean’ threw exception; nested exception is com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
20170218 08:47:10.424 ERROR [application name used to be here…,,,] 1 [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ’embeddedServletContainerCustomizerBeanPostProcessor’: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cache.annotation.ProxyCachingConfiguration’: Unsatisfied dependency expressed through method ‘setConfigurers’ parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cloud.aws.cache.config.annotation.ElastiCacheCachingConfiguration’: Unsatisfied dependency expressed through field ‘stackResourceFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘stackResourceRegistryFactoryBean’ defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration$StackAutoDetectConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method ‘stackResourceRegistryFactoryBean’ threw exception; nested exception is com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:478) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:240) ~[springcontext4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:697) ~[springcontext4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:526) ~[springcontext4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[springboot1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [springboot1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [springboot1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [springboot1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [springboot1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [springboot1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
    at biz.te2.platform.services.delivery.PeoplePickerDeliveryServiceApplication.main(PeoplePickerDeliveryServiceApplication.java:11) [classes!/:1.0.0SNAPSHOT]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [messagedeliverypeoplepickercore.jar:1.0.0SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [messagedeliverypeoplepickercore.jar:1.0.0SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [messagedeliverypeoplepickercore.jar:1.0.0SNAPSHOT]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [messagedeliverypeoplepickercore.jar:1.0.0SNAPSHOT]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cache.annotation.ProxyCachingConfiguration’: Unsatisfied dependency expressed through method ‘setConfigurers’ parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cloud.aws.cache.config.annotation.ElastiCacheCachingConfiguration’: Unsatisfied dependency expressed through field ‘stackResourceFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘stackResourceRegistryFactoryBean’ defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration$StackAutoDetectConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method ‘stackResourceRegistryFactoryBean’ threw exception; nested exception is com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:648) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92) ~[springaop4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:101) ~[springaop4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:85) ~[springaop4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103) ~[springaop4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:249) ~[springaop4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:993) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:964) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:472) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    … 22 common frames omitted
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.springframework.cloud.aws.cache.config.annotation.ElastiCacheCachingConfiguration’: Unsatisfied dependency expressed through field ‘stackResourceFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘stackResourceRegistryFactoryBean’ defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration$StackAutoDetectConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method ‘stackResourceRegistryFactoryBean’ threw exception; nested exception is com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:349) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1286) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1255) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1161) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1056) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    … 48 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘stackResourceRegistryFactoryBean’ defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration$StackAutoDetectConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method ‘stackResourceRegistryFactoryBean’ threw exception; nested exception is com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1023) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1128) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1056) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:566) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    … 73 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean]: Factory method ‘stackResourceRegistryFactoryBean’ threw exception; nested exception is com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    … 85 common frames omitted
Caused by: com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain
    at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:131) ~[awsjavasdkcore1.11.18.jar!/:na]
    at com.amazonaws.http.AmazonHttpClient.getCredentialsFromContext(AmazonHttpClient.java:781) ~[awsjavasdkcore1.11.18.jar!/:na]
    at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:807) ~[awsjavasdkcore1.11.18.jar!/:na]
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:702) ~[awsjavasdkcore1.11.18.jar!/:na]
    at com.amazonaws.http.AmazonHttpClient.doExecute(AmazonHttpClient.java:454) ~[awsjavasdkcore1.11.18.jar!/:na]
    at com.amazonaws.http.AmazonHttpClient.executeWithTimer(AmazonHttpClient.java:416) ~[awsjavasdkcore1.11.18.jar!/:na]
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:365) ~[awsjavasdkcore1.11.18.jar!/:na]
    at com.amazonaws.services.cloudformation.AmazonCloudFormationClient.doInvoke(AmazonCloudFormationClient.java:1633) ~[awsjavasdkcloudformation1.11.18.jar!/:na]
    at com.amazonaws.services.cloudformation.AmazonCloudFormationClient.invoke(AmazonCloudFormationClient.java:1603) ~[awsjavasdkcloudformation1.11.18.jar!/:na]
    at com.amazonaws.services.cloudformation.AmazonCloudFormationClient.describeStackResources(AmazonCloudFormationClient.java:892) ~[awsjavasdkcloudformation1.11.18.jar!/:na]
    at org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider.autoDetectStackName(AutoDetectingStackNameProvider.java:76) ~[springcloudawscore1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider.afterPropertiesSet(AutoDetectingStackNameProvider.java:62) ~[springcloudawscore1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider.<init>(AutoDetectingStackNameProvider.java:52) ~[springcloudawscore1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at org.springframework.cloud.aws.core.env.stack.config.AutoDetectingStackNameProvider.<init>(AutoDetectingStackNameProvider.java:56) ~[springcloudawscore1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration$StackAutoDetectConfiguration.stackResourceRegistryFactoryBean(ContextStackAutoConfiguration.java:71) ~[springcloudawsautoconfigure1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration$StackAutoDetectConfiguration$$EnhancerBySpringCGLIB$$bbb47f74.CGLIB$stackResourceRegistryFactoryBean$0(<generated>) ~[springcloudawsautoconfigure1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration$StackAutoDetectConfiguration$$EnhancerBySpringCGLIB$$bbb47f74$$FastClassBySpringCGLIB$$f7d4da5e.invoke(<generated>) ~[springcloudawsautoconfigure1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[springcore4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[springcontext4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    at org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration$StackAutoDetectConfiguration$$EnhancerBySpringCGLIB$$bbb47f74.stackResourceRegistryFactoryBean(<generated>) ~[springcloudawsautoconfigure1.1.3.RELEASE.jar!/:1.1.3.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[springbeans4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
    … 86 common frames omitted


禁用 ContextStackAutoConfiguration
通过如下更新我的@SpringBootApplication:@SpringBootApplication(exclude = ContextStackAutoConfiguration.class)


您的代码似乎是正确的,但最好查看完整的类和堆栈跟踪,以确保在实例化客户端时确实产生了异常。可能在后台创建了一些其他需要凭据的客户端。不过,我确实对您的部署环境有一些建议。

您应该使用 EC2 实例配置文件或 ECR 任务角色(如果您使用 ECR)来访问 AWS。将凭据直接传递给代码存在安全风险,应在生产中避免。仅在尝试访问跨账户资源时使用凭据。假设外部 IAM 角色也是首选。


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/267599.html

(0)
上一篇 2022年6月18日
下一篇 2022年6月18日

相关推荐

发表回复

登录后才能评论