serverless: 'name.replace is not a function' while serverless deploy

#This is a (Bug Report)

Description

When I run serverless deploy in a n AWS Lambda project that has python library (Pillow - for image processing) dependencies, I get the following deployment error.

For bug reports:

  • What went wrong? serverless deploy didnt work.
  • What did you expect should have happened? The deployment should have been successful and the lambda function should have worked.
  • What stacktrace or error message from your provider did you see?

Additional Data

  • Serverless Framework Version you’re using: 1.21.0
  • Operating System: Mac 10.12.6 Sierra
  • Stack Trace:
> serverless deploy -v

Serverless: Parsing Python requirements.txt
Serverless: Installing required Python packages for runtime python2.7...
Serverless: Docker Image: lambci/lambda:build-python2.7
Serverless: Linking required Python packages...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Unlinking required Python packages...

  Type Error ---------------------------------------------

    name.replace is not a function

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

TypeError: name.replace is not a function
    at Object.normalizeNameToAlphaNumericOnly (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/aws/lib/naming.js:32:36)
    at Object.normalizeBucketName (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/aws/lib/naming.js:200:17)
    at Object.getLambdaS3PermissionLogicalId (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/aws/lib/naming.js:263:8)
    at s3EnabledFunctions.forEach.s3EnabledFunction (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/s3/index.js:189:10)
    at Array.forEach (<anonymous>)
    at AwsCompileS3Events.compileS3Events (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/s3/index.js:167:24)
    at BbPromise.reduce (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/classes/PluginManager.js:242:55)
From previous event:
    at PluginManager.invoke (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/classes/PluginManager.js:242:22)
    at PluginManager.spawn (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/classes/PluginManager.js:254:17)
    at Deploy.BbPromise.bind.then.then (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:101:50)
From previous event:
    at Object.before:deploy:deploy [as hook] (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/plugins/deploy/deploy.js:99:10)
    at BbPromise.reduce (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/classes/PluginManager.js:242:55)
From previous event:
    at PluginManager.invoke (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/classes/PluginManager.js:242:22)
    at PluginManager.run (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/classes/PluginManager.js:261:17)
    at variables.populateService.then (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/Serverless.js:99:33)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
From previous event:
    at Serverless.run (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/lib/Serverless.js:86:74)
    at serverless.init.then (/Users/vkumar/.nvm/versions/node/v8.1.3/lib/node_modules/serverless/bin/serverless:39:50)
    at <anonymous>


  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.3.0
     Serverless Version:     1.21.0
  • Provider Error messages: ‘name.replace is not a function’

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 24 (4 by maintainers)

Most upvoted comments

I had same issue. I don’t suppose serverless.yml supports “Ref” in events[].s3.bucket.

    events:
      - s3:
          bucket:
            Ref: ServerlessDeploymentBucket // not supported`

@JonChristensen Thanks, but that library leads to corrupted deployments as its need to be done in two steps 😞

Anyway, I solved it by completely ignoring the serverless features and instead of using events.s3 in function definition, we are defining the function ARN in bucket’s template:

  Bucket: {
    Type: 'AWS::S3::Bucket',
    Properties: {
      BucketName: 'bucket-name',
      NotificationConfiguration: {
        LambdaConfigurations: [
          {
            Event: 's3:ObjectCreated:Put',
            Function: { 'Fn::GetAtt': ['FooLambdaFunction', 'Arn'] }
          }
        ]
      }
    }

I have the same issue. It looks like it is because we are trying to make reference to the ServerlessDeploymentBucket. Is there a better way to reference this bucket arn predictably?

I am trying to set up a Lambda event triggered by s3 whenever there is a deploy from serverless. I need to create RDS tables via Lambda whenever a user deploys a new instance.

I’m running into this same issue.

service: importer
frameworkVersion: "=1.19.0"

plugins:
  - serverless-plugin-scripts
  - serverless-python-requirements

custom:
  stage: dev
  pythonRequirements:
    dockerizePip: true
  scripts:
    hooks:
      'before:package:cleanup': rm -fr __pycache__
      'before:package:createDeploymentArtifacts': rm -fr .requirements/pandas/tests && rm -fr .requirements/psycopg2/tests && find . -name '*.pyc' -type f -delete
      'before:deploy:function:packageFunction': rm -fr .requirements/pandas/tests && rm -fr .requirements/psycopg2/tests && find . -name '*.pyc' -type f -delete

provider:
  name: aws
  runtime: python3.6
  stage: ${self:custom.stage}
  region: us-east-1

  memorySize: 128
  timeout: 300

  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - "s3:ListBucket"
      Resource:
        Fn::Join:
          - ""
          - - "arn:aws:s3:::"
            - Ref: ServerlessDeploymentBucket
    - Effect: "Allow"
      Action:
        - "lambda:InvokeFunction"
      Resource: "*"
    - Effect: "Allow"
      Action:
        - "s3:GetObject"
      Resource: "*"
    - Effect: "Allow"
      Action:
        - "s3:PutObject"
        - "s3:DeleteObject"
      Resource:
        Fn::Join:
          - ""
          - - "arn:aws:s3:::"
            - Ref: ServerlessDeploymentBucket
            - "/*"

  package:
    exclude:
      - .git/**
      - node_modules/**
      - __pycache__/**

functions:
  data_importer:
    handler: handler.import_data
    events:
      - s3:
          bucket:
            Ref: ServerlessDeploymentBucket
          event: s3:ObjectCreated:*
          rules:
            - prefix: firehose/

resources:
  Resources:
    scraperStream:
      Type: AWS::Kinesis::Stream
      Properties:
        ShardCount: 6
        RetentionPeriodHours: 24
    scraperFirehoseDeliveryRole:
      Type: AWS::IAM::Role
      Properties:
        AssumeRolePolicyDocument:
          Version: "2012-10-17"
          Statement:
            - Sid: ''
              Effect: Allow
              Principal:
                Service: firehose.amazonaws.com
              Action: 'sts:AssumeRole'
              Condition:
                StringEquals:
                  "sts:ExternalId":
                    "Ref": AWS::AccountId
    scraperFirehoseDeliveryPolicy:
      Type: AWS::IAM::Policy
      Properties:
        PolicyName: firehose_delivery_policy
        PolicyDocument:
          Version: "2012-10-17"
          Statement:
            - Effect: Allow
              Action:
                - 's3:AbortMultipartUpload'
                - 's3:GetBucketLocation'
                - 's3:GetObject'
                - 's3:ListBucket'
                - 's3:ListBucketMultipartUploads'
                - 's3:PutObject'
              Resource:
                - Fn::Join:
                  - ""
                  - - "arn:aws:s3:::"
                    - Ref: ServerlessDeploymentBucket
                - Fn::Join:
                  - ""
                  - - "arn:aws:s3:::"
                    - Ref: ServerlessDeploymentBucket
                    - "/firehose/*"
        Roles:
          - Ref: scraperDeliveryRole
# Eggs available on Lambda
boto3==1.4.7 #no-deploy
botocore==1.7.7 #no-deploy
docutils==0.14 #no-deploy
jmespath==0.9.3 #no-deploy
python-dateutil==2.6.1 #no-deploy
s3transfer==0.1.11 #no-deploy
six==1.10.0 #no-deploy

pandas==0.20.3
numpy==1.13.1
beautifulsoup4==4.6.0
requests==2.18.4
decorator==4.1.2
inflection==0.3.1
SQLAlchemy==1.1.14
psycopg2==2.7.3.1
SQLAlchemy-Utils==0.32.16

Not sure if others are still grappling with this, but it looks as thought serverless has a flag to allow for pre-existing buckets:

functions:
  users:
    handler: users.handler
    events:
      - s3:
          bucket: legacy-photos
          event: s3:ObjectCreated:*
          rules:
            - prefix: uploads/
            - suffix: .jpg
          existing: true   <----------------------------------

I also ran into the same issue. any update on this? screenshot from 2018-06-03 16-00-47

But what if you are making a bucket while trying to reference it in one of your functions? When I use the existing flag it always fails to delete due to a race condition.