无服务器 - AWS S3 Bucket 已经存在
Serverless - AWS S3 Bucket already exists
我正在构建我的第一个 sls 应用程序,我正在尝试创建两个存储桶。 “LogosBucket”完美运行。我执行了相同的过程来创建第二个名为“DocumentsBucket”的过程,但失败并显示消息:“发生错误:DocumentsBucket - documents-bucket-dev 已经存在。”
我查看了 Stack,它没有在资源下列出。我知道这个问题发生在桶事件中,但我不认为这是我的情况。这感觉像是一个非常简单的疏忽,但我有点迷茫。
这是我的 serverless.yml 文件:
iamRoleStatements:
- ${file(iam/LogosBucketIAM.yml):LogosBucketIAM}
- ${file(iam/DocumentsBucketIAM.yml):DocumentsBucketIAM}
resources:
Resources:
LogosBucket: ${file(resources/LogosBucket.yml):LogosBucket}
LogosBucketPolicy: ${file(resources/LogosBucket.yml):LogosBucketPolicy}
DocumentsBucket: ${file(resources/DocumentsBucket.yml):DocumentsBucket}
DocumentsBucketPolicy: ${file(resources/DocumentsBucket.yml):DocumentsBucketPolicy}
...
custom:
LogosBucket:
name: logos-bucket-${self:provider.stage}
DocumentsBucket:
name: documents-bucket-${self:provider.stage}
DocumentsBucketIAM.yml:
DocumentsBucketIAM:
Effect: Allow
Action:
- s3:PutObject
Resource: arn:aws:s3:::${self:custom.DocumentsBucket.name}/*
LogosBucketIAM.yml:
LogosBucketIAM:
Effect: Allow
Action:
- s3:PutObject
Resource: arn:aws:s3:::${self:custom.LogosBucket.name}/*
DocumentsBucket.yml:
DocumentsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.DocumentsBucket.name}
DocumentsBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref DocumentsBucket
PolicyDocument:
Statement:
- Sid: PublicRead
Effect: Allow
Principal: '*'
Action:
- s3:GetObject
Resource: arn:aws:s3:::${self:custom.DocumentsBucket.name}/*
LogosBucket.yml:
LogosBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.LogosBucket.name}
LogosBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref LogosBucket
PolicyDocument:
Statement:
- Sid: PublicRead
Effect: Allow
Principal: '*'
Action:
- s3:GetObject
Resource: arn:aws:s3:::${self:custom.LogosBucket.name}/*
如果有任何帮助 and/or 调试 sls 的提示,我将不胜感激。谢谢!
S3 是一个通用命名空间,这意味着您创建的每个 S3 存储桶都必须有一个唯一的名称,该名称不能被世界上任何其他人使用。这是因为您的存储桶名称构成了您的 S3 url 的一部分,它必须是唯一的。
我正在构建我的第一个 sls 应用程序,我正在尝试创建两个存储桶。 “LogosBucket”完美运行。我执行了相同的过程来创建第二个名为“DocumentsBucket”的过程,但失败并显示消息:“发生错误:DocumentsBucket - documents-bucket-dev 已经存在。”
我查看了 Stack,它没有在资源下列出。我知道这个问题发生在桶事件中,但我不认为这是我的情况。这感觉像是一个非常简单的疏忽,但我有点迷茫。
这是我的 serverless.yml 文件:
iamRoleStatements:
- ${file(iam/LogosBucketIAM.yml):LogosBucketIAM}
- ${file(iam/DocumentsBucketIAM.yml):DocumentsBucketIAM}
resources:
Resources:
LogosBucket: ${file(resources/LogosBucket.yml):LogosBucket}
LogosBucketPolicy: ${file(resources/LogosBucket.yml):LogosBucketPolicy}
DocumentsBucket: ${file(resources/DocumentsBucket.yml):DocumentsBucket}
DocumentsBucketPolicy: ${file(resources/DocumentsBucket.yml):DocumentsBucketPolicy}
...
custom:
LogosBucket:
name: logos-bucket-${self:provider.stage}
DocumentsBucket:
name: documents-bucket-${self:provider.stage}
DocumentsBucketIAM.yml:
DocumentsBucketIAM:
Effect: Allow
Action:
- s3:PutObject
Resource: arn:aws:s3:::${self:custom.DocumentsBucket.name}/*
LogosBucketIAM.yml:
LogosBucketIAM:
Effect: Allow
Action:
- s3:PutObject
Resource: arn:aws:s3:::${self:custom.LogosBucket.name}/*
DocumentsBucket.yml:
DocumentsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.DocumentsBucket.name}
DocumentsBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref DocumentsBucket
PolicyDocument:
Statement:
- Sid: PublicRead
Effect: Allow
Principal: '*'
Action:
- s3:GetObject
Resource: arn:aws:s3:::${self:custom.DocumentsBucket.name}/*
LogosBucket.yml:
LogosBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.LogosBucket.name}
LogosBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref LogosBucket
PolicyDocument:
Statement:
- Sid: PublicRead
Effect: Allow
Principal: '*'
Action:
- s3:GetObject
Resource: arn:aws:s3:::${self:custom.LogosBucket.name}/*
如果有任何帮助 and/or 调试 sls 的提示,我将不胜感激。谢谢!
S3 是一个通用命名空间,这意味着您创建的每个 S3 存储桶都必须有一个唯一的名称,该名称不能被世界上任何其他人使用。这是因为您的存储桶名称构成了您的 S3 url 的一部分,它必须是唯一的。