spring-当来自 EC2 的 运行 时,cloud-aws 无法将文件放入 S3
spring-cloud-aws not able to put files to S3 when run from EC2
我正在尝试使用 AmazonS3Client 通过 Spring 引导应用程序将一些文件放入 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:用户:arn:aws:iam::560600000009:user/test_user1 无权执行:cloudformation:DescribeStackResources(服务:AmazonCloudFormation;状态代码:403 ; 错误代码:拒绝访问;
在 EC2 实例中从代码 运行ning 访问 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 在我的服务中自动连接 class。
@Autowired
public FileService(AmazonS3Client s3Client) {..}
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。
我正在尝试使用 AmazonS3Client 通过 Spring 引导应用程序将一些文件放入 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:用户:arn:aws:iam::560600000009:user/test_user1 无权执行:cloudformation:DescribeStackResources(服务:AmazonCloudFormation;状态代码:403 ; 错误代码:拒绝访问;
在 EC2 实例中从代码 运行ning 访问 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 在我的服务中自动连接 class。
@Autowired
public FileService(AmazonS3Client s3Client) {..}
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。