【问题标题】:Serverless Framework creating extra characters for S3 Bucket from CloudFormation Template无服务器框架从 CloudFormation 模板为 S3 存储桶创建额外字符
【发布时间】:2020-12-14 19:20:32
【问题描述】:

所以,我猜这可能有一个直截了当的答案(希望),但我正在尝试创建一个 AWS Lambda 函数来处理 csv 文件并将处理后的文件放在不同的 s3 存储桶中(取决于什么正在转换和生成)。

在执行此操作时,我使用无服务器框架和 CloudFormation,但我注意到在创建存储桶时,它们附加了无关的值以及服务名称。例如:

桶: new-process-2-dev-companyprocessedsalestotal08252-jdgsd2ljyqpx

本来就是: companyprocessedsalestotal08252

Yaml 文件位于下方,我使用 CloudFormation 资源生成其他存储桶。我该如何解决这个命名约定?

service: new-process-2

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

resources:
  Resources:
    companyincoming08252020:
      Type: 'AWS::S3::Bucket'
      Properties: {}
    companyprocessedsalestotal08252020:
      Type: 'AWS::S3::Bucket'
      Properties: {}
    compnayprocessedwinloss08252020:
      Type: 'AWS::S3::Bucket'
      Properties: {}
    companyemployeestargetotal08252020:
      Type: 'AWS::S3::Bucket'
      Properties: {}
    companyemployeesalespivot08252020:
      Type: 'AWS::S3::Bucket'
      Properties: {}



provider:
  name: aws
  runtime: python3.8
  region: us-east-1
  profile: serverless-admin
  timeout: 120
  memorySize: 128
  iamRoleStatements:
   - Effect: "Allow"
     Action:
       - "s3:*"
     Resource: "*"


functions:
  csv-processor:
    handler: handler.featureengineering
    events:
      - s3:
          bucket: companyincoming08252020
          event: s3:ObjectCreated:*
          rules:
            - suffix: .csv

custom:
  pythonRequirements:
  dockerizePip: true




plugins:
  - serverless-python-requirements
  - serverless-s3-deploy

【问题讨论】:

    标签: amazon-s3 aws-lambda yaml amazon-cloudformation serverless-framework


    【解决方案1】:

    需要为正在创建的存储桶定义名称属性。如果省略,则 CloudFormation 将为存储桶生成一个名称:

    如果您不指定名称,AWS CloudFormation 会生成一个唯一 ID 并将该 ID 用作存储桶名称

    在 CFT 中,属性是 BucketName,或者如果在无服务器文件中定义,那么这只是 name

    此处为 CFT 信息:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-name

    这里的无服务器信息:https://www.serverless.com/framework/docs/providers/aws/events/s3#custom-bucket-configuration

    【讨论】:

    • 此外,S3 存储桶名称必须是通用唯一的(不仅仅是在您的账户中唯一),因此通常最好让 AWS 为您“唯一”名称。
    猜你喜欢
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 2017-11-24
    相关资源
    最近更新 更多