JLuu
JLuu

Reputation: 373

Error in Yaml file while trying to create multiple s3 buckets in Serverless Framework for AWS Lambda Function

So I'm pretty new to CloudFormation and also to Serverless framework. I've been trying to work through some exercises (such as an automatic thumbnail generator) and then create some simple projects that I can hopefully generalize for my own purposes.

Right now I'm attempting create a stack/function that creates two S3 buckets and has the Lambda Function take a CSV file form one, perform some simple transformations, and place it in the other receiving bucket.

In trying to build off the exercise I've done, I created a Yaml file with the following code:

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


custom:
  assets:
    targets:
    - bucket1: csvbucket1-08-16-2020
      pythonRequirements:
      dockerizePip: true
    - bucket2: csvbucket2-08-16-2020
      pythonRequirements:
      dockerizePip: true

functions:
  protomodel-readcsv:
    handler: handler.readindata
    events:
      s3:
      - bucket: ${self:custom.bucket1}
        event: s3:ObjectCreated:*
        suffix: .csv
      - bucket: ${self:custom.bucket2}
        

     

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

However, when i do a Serverless deploy from my command prompt, I get:

 Serverless Warning --------------------------------------

  A valid service attribute to satisfy the declaration 'self:custom.bucket1' could not be found.


 Serverless Warning --------------------------------------

  A valid service attribute to satisfy the declaration 'self:custom.bucket2' could not be found.


  Serverless Error ---------------------------------------

  Events for "protomodel-readcsv" must be an array, not an object

I've tried to make the events object in the protohandler-readcsv: by adding a - but I then get a bad indentation error that for some reason I cannot reconcile. But, more fundamentally, I'm not exactly sure why that item would need be an array anyway, and I wasn't clear about the warnings with the buckets either.

So sorry about a pretty newbie question about this, but running tutorials/examples online leaves a lot to try to figure out in trying to generalize/customize these examples.

Upvotes: 1

Views: 631

Answers (1)

Traycho Ivanov
Traycho Ivanov

Reputation: 3217

custom:
  assets:
    targets:
    - bucket1

I guess you need self:custom.assets.targets.bucket1, not sure if this nested assets will work.

Please check the example below is supposed to work.

service: MyService
custom:
  deploymentBucket: s3_my_bucket

provider:
  name: aws
  deploymentBucket: ${self:custom.deploymentBucket}
  stage: dev

Upvotes: 1

Related Questions