从EC2

时间:2015-10-01 09:12:27

标签: amazon-s3 spring-boot spring-cloud

我正在尝试使用AmazonS3Client通过我的Spring Boot应用程序将一些文件放入S3存储桶中。在AWS中,我创建了一个IAM用户(test_user1)并授予该用户S3完全访问权限。同样在S3中,我向该用户授予了“s3:*”操作。在我的配置文件中为cloud.aws.credentials.accessKey和cloud.aws.credentials.secretKey指定了相同的用户凭据。

当我从本地计算机运行应用程序时,它运行正常。我可以在S3存储桶中放入多个文件并查看文件。

但是,当从AWS EC2实例运行相同的应用程序时,我会在应用程序启动时出现以下错误:

引起:org.springframework.beans.BeanInstantiationException:无法实例化org.springframework.cloud.aws.core.env.stack.config.StackResourceRegistryFactoryBean ]:工厂方法'stackResourceRegistryFactoryBean'引发异常;嵌套异常是com.amazonaws.AmazonServiceException:User:arn:aws:iam :: 560600000009:user / test_user1无权执行: cloudformation:DescribeStackResources (服务:AmazonCloudFormation;状态代码:403;错误代码:AccessDenied;

从EC2实例中运行的代码访问S3时,是否还需要设置其他内容?我没有使用Amazon Cloud Formation。

以下是我的项目的样子:

build.gradle:

compile 'org.springframework.cloud:spring-cloud-aws-autoconfigure:1.0.3.RELEASE'
compile 'org.springframework.cloud:spring-cloud-aws-context:1.0.3.RELEASE'

application.yml:

bucket: test-bucket-1
cloud.aws.credentials.accessKey: AxxxxxxxxxxxxxxA
cloud.aws.credentials.secretKey: jxxxxxxxxxxxxxxR
cloud.aws.credentials.instanceProfile:  true

AmazonS3Client在我的服务类中自动装配。

@Autowired
public FileService(AmazonS3Client s3Client) {..}

1 个答案:

答案 0 :(得分:24)

Spring Cloud AWS尝试自动配置CloudFormation(当应用程序在EC2中运行时)。

我解决了这个错误,在application.properties

中禁用了autoconf
cloud.aws.stack.auto=false

阅读本文以获取更多信息http://cloud.spring.io/spring-cloud-aws/spring-cloud-aws.html#_automatic_cloudformation_configuration

最后:抱歉我的英文