JLuu
JLuu

Reputation: 373

Serverless Framework creating extra characters for S3 Bucket from CloudFormation Template

So, i'm guessing there is probably a straight forward answer to this (hoping), but I'm attempting to create a AWS Lambda function that processes csv files and places the processed files in different s3 buckets (depending on what is being transformed and generated).

In doing this, I'm using Serverless Framework and CloudFormation, but am noticing that the when the buckets are being created, they have extraneous values attached to them along with the service name. For instance:

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

was really meant to just be: companyprocessedsalestotal08252

The Yaml file is down bellow, and I used the CloudFormation resources to generate the other buckets. How do I solve this naming convetion?

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

Upvotes: 0

Views: 462

Answers (1)

Will
Will

Reputation: 320

The name property needs to be defined for the buckets being created. If this is omitted then CloudFormation will generate a name for the bucket:

If you don't specify a name, AWS CloudFormation generates a unique ID and uses that ID for the bucket name

Within a CFT the property is BucketName or if defined in the serverless file then this is just name

CFT info here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-name

Serverless info here: https://www.serverless.com/framework/docs/providers/aws/events/s3#custom-bucket-configuration

Upvotes: 2

Related Questions