gpt4 book ai didi

amazon-s3 - 从 EC2 运行时,sp​​ring-cloud-aws 无法将文件放入 S3

转载 作者:行者123 更新时间:2023-12-04 01:31:52 26 4
gpt4 key购买 nike

我正在尝试使用 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。

这是我的项目的样子:

构建.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'

应用程序.yml:
bucket: test-bucket-1
cloud.aws.credentials.accessKey: AxxxxxxxxxxxxxxA
cloud.aws.credentials.secretKey: jxxxxxxxxxxxxxxR
cloud.aws.credentials.instanceProfile: true

AmazonS3Client 在我的服务类中 Autowiring 。
@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 .

关于amazon-s3 - 从 EC2 运行时,sp​​ring-cloud-aws 无法将文件放入 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32883702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com