sou*_*ikc 18 amazon-web-services spring-boot aws-sdk
当我尝试在本地运行Spring boot-AWS应用程序时,我收到以下错误:
没有可用的EC2元数据,因为应用程序未在EC2环境中运行.仅当应用程序在EC2实例上运行时,才能进行区域检测
我的aws-config.xml如下所示:
<aws-context:context-credentials>
<aws-context:simple-credentials access-key="*****" secret-key="*****"/>
</aws-context:context-credentials>
<aws-context:context-region auto-detect="false" region="ap-south-1" />
<aws-context:context-resource-loader/>
<aws-messaging:annotation-driven-queue-listener max-number-of-messages="10" wait-time-out="20" visibility-timeout="3600"/>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用以下类中的SQSListner进行监听:
@Configuration
@EnableSqs
@ImportResource("classpath:/aws-config.xml")
@EnableRdsInstance(databaseName = "******",
dbInstanceIdentifier = "*****",
password = "******")
public class AwsResourceConfig {
@SqsListener(value = "souviksqs", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void receiveNewFileUpload(S3EventNotification event) {
try {
if ( event != null && !CollectionUtils.isNullOrEmpty( event.getRecords() ) && event.getRecords().get( 0 ) != null ) {
S3Entity entry = event.getRecords().get(0).getS3();
System.out.println("############ File Uploaded to ###################### " + entry.getBucket().getName() + "/" + entry.getObject().getKey());
}
} catch (Exception e) {
System.out.println("Error reading the SQS message " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
}
编辑:刚才注意到当我包含以下aws-messaging maven依赖时出现错误:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-messaging</artifactId>
<version>${spring-cloud-aws-version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我使用的是spring-cloud-aws-version - 1.2.1.RELEASE
Shu*_*dey 42
我使用springframework.cloud.aws.autoconfigure,遇到了同样的问题.其背后的原因是,当我们在非AWS环境中运行应用程序时,我们需要手动配置区域,即.本地.所以把这个属性放在你的application-local.properties中,你应该很好.
cloud.aws.region.static =美国 - 东 - 1
如果使用 application.yml 我做了以下
spring:
application:
name: App Name
autoconfigure:
exclude:
- org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
Run Code Online (Sandbox Code Playgroud)
找到了问题。我正在使用spring-cloud-starter-aws-messaging进行SQS消息传递。上面的依赖项包括许多自动检测类,即使它们不是必需的,它们最终也会触发。
相反,我使用spring-cloud-aws-messaging来解决该问题以及许多其他自动检测问题。
小智 5
在 spring boot proj 中将这些属性添加到我的 application.properties 帮助了我。
cloud.aws.region.static=us-west-2
cloud.aws.region.auto=false
cloud.aws.stack.auto=false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8079 次 |
| 最近记录: |