question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model validation failed (#/EventSourceArn: failed validation constraint for keyword [pattern])

See original GitHub issue

When I want to publish my functions with last version of serverless (2.18.0) I have this error for function using sqs event with arn directly setted :

Model validation failed (#/EventSourceArn: failed validation constraint for keyword [pattern])

When I try in previous version (2.16.1) It works fine

service: my-service

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${opt:stage, 'dev'}
  profile: ${env:AWS_DEFAULT_PROFILE}
  region: eu-west-1
  memorySize: 1024
  timeout: 60
  logRetentionInDays: ${self:custom.${opt:stage, 'dev'}.RetentionInDays}
  iamRoleStatements:
    - Effect: "Allow"
      Action:
        - cloudwatch:*
        - cloudformation:*
        - ec2:*
        - events:*
        - iot:*
        - lambda:*
        - rds:*
        - route53:*
        - s3:*
        - sns:*
        - sqs:*
        - tag:*
        - es:*
        - xray:*
        - apigateway:*
        - elasticloadbalancing:*
      Resource: "*"
  vpc: ${self:custom.${opt:stage, 'dev'}.vpc}
  environment:
    NODE_ENV: production
    WIRES_ENV: ${self:custom.${opt:stage, 'dev'}.WIRES_ENV}

custom:
  dev:
    accountId : 0123456789345
    WIRES_ENV: development
    RetentionInDays: 30
    moduleLayer: arn:aws:lambda:eu-west-1:0123456789345:layer:serverless-module-dev:12
    vpc:
      securityGroupIds:
        - sg-xxxxxxxxxxxxxxxxx
      subnetIds:
        - subnet-xxxxxxxxxxxxxxxxx
        - subnet-xxxxxxxxxxxxxxxxx
        - subnet-xxxxxxxxxxxxxxxxx
  prune:
    automatic: true
    number: 3

package:
  individually: true
  exclude:
    - node_modules/**
    - wires.*.json
    - claudia/**
    - core/test/**
    - invoke/**
    - test/**
    - tests/**
    - graphite-storage-schemas/**
    - sources/**
    - scripts/**
    - migrations/**
    - modules/**/test/**
    - '*.js'
    - '.nyc_output/**'
    - '.vscode/**'
    - '.editorconfig'
    - '.eslintignore'
    - '.eslintrc'
    - '.gitignore'
    - '.npmignore'
    - 'jsconfig.json'
    - README.md
    - .DS_Store
    - '**/.DS_Store'
  include:
    - _init.js
    - package.json
    - wires-defaults.json
    - wires.${self:custom.${opt:stage, 'dev'}.WIRES_ENV}.json

functions:
  my-function:
    handler: my-function.handler
    reservedConcurrency: 5
    package:
      individually: true
      include:
        - my-function.js
    layers:
      - ${self:custom.${opt:stage, 'dev'}.moduleLayer}
    events:
      - sqs: arn:aws:sqs:eu-west-1:${self:custom.${opt:stage, 'dev'}.accountId}:${self:custom.${opt:stage, 'dev'}.WIRES_ENV}-test

plugins:
  - serverless-prune-plugin

Serverless Warning --------------------------------------
 
  A valid environment variable to satisfy the declaration 'env:AWS_DEFAULT_PROFILE' could not be found.
 
Serverless: Deprecation warning: Starting with next major version, default value of provider.lambdaHashingVersion will be equal to "20201221"
            More Info: https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
Serverless: Deprecation warning: Starting with next major version, API Gateway naming will be changed from "{stage}-{service}" to "{service}-{stage}".
            Set "provider.apiGateway.shouldStartNameWithService" to "true" to adapt to the new behavior now.
            More Info: https://www.serverless.com/framework/docs/deprecations/#AWS_API_GATEWAY_NAME_STARTING_WITH_SERVICE
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service my-function.zip file to S3 (322.64 KB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - serverless-dev
CloudFormation - UPDATE_IN_PROGRESS - AWS::S3::BucketPolicy - ServerlessDeploymentBucketPolicy
CloudFormation - UPDATE_COMPLETE - AWS::S3::BucketPolicy - ServerlessDeploymentBucketPolicy
CloudFormation - UPDATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - UPDATE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - MyDashFunctionLambdaFunction
CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - MyDashFunctionLambdaFunction
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - MyDashFunctionLambdaVersionpfFLqPl6dceyKRrLZYMakXPRNalRIGvyAl96c2l4nM
CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - MyDashFunctionLambdaVersionpfFLqPl6dceyKRrLZYMakXPRNalRIGvyAl96c2l4nM
CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - MyDashFunctionLambdaVersionpfFLqPl6dceyKRrLZYMakXPRNalRIGvyAl96c2l4nM
CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::EventSourceMapping - MyDashFunctionEventSourceMappingSQSDevelopmentmeasures
CloudFormation - UPDATE_FAILED - AWS::Lambda::EventSourceMapping - MyDashFunctionEventSourceMappingSQSDevelopmentmeasures
CloudFormation - UPDATE_ROLLBACK_IN_PROGRESS - AWS::CloudFormation::Stack - serverless-dev
CloudFormation - UPDATE_IN_PROGRESS - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - UPDATE_IN_PROGRESS - AWS::S3::BucketPolicy - ServerlessDeploymentBucketPolicy
CloudFormation - UPDATE_COMPLETE - AWS::S3::BucketPolicy - ServerlessDeploymentBucketPolicy
CloudFormation - UPDATE_COMPLETE - AWS::IAM::Role - IamRoleLambdaExecution
CloudFormation - UPDATE_IN_PROGRESS - AWS::Lambda::Function - MyDashFunctionLambdaFunction
CloudFormation - UPDATE_COMPLETE - AWS::Lambda::Function - MyDashFunctionLambdaFunction
CloudFormation - UPDATE_COMPLETE - AWS::Lambda::EventSourceMapping - MyDashFunctionEventSourceMappingSQSDevelopmentmeasures
CloudFormation - UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - serverless-dev
CloudFormation - DELETE_SKIPPED - AWS::Lambda::Version - MyDashFunctionLambdaVersionpfFLqPl6dceyKRrLZYMakXPRNalRIGvyAl96c2l4nM
CloudFormation - DELETE_COMPLETE - AWS::Lambda::EventSourceMapping - MyDashFunctionEventSourceMappingSQSDevelopmentmeasures
CloudFormation - UPDATE_ROLLBACK_COMPLETE - AWS::CloudFormation::Stack - serverless-dev
Serverless: Operation failed!

Installed version

2.18.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:26 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
kolinekpcommented, Feb 15, 2021

@throrin19: I had the same problem and according to your serverless.yml, it might be caused by the same cause.

I have noticed, you are also using a custom variable to store your AccountId and it also starts with a 0. Can you try wrapping your AccountId value in single quotes? accountId : '0123456789345'

I believe the value gets interpreted as a number, and all the leading zeroes gets removed. You can also confirm it when inspecting the final CloudFormation template which should be a part of your ServerlessDeploymentBucket.

2reactions
throrin19commented, Jan 29, 2021

@pgrzesik haha it’s seems the same. My account ID start with 0

Read more comments on GitHub >

github_iconTop Results From Across the Web

failed validation constraint for keyword [pattern]) - Stack Overflow
In AWS cloud formation, I am facing below validation error: Model validation failed (#/EventSourceArn: failed validation ...
Read more >
failed validation constraint for keyword [pattern]) · Issue #1699 ...
Description: Unable to create stack with example generated during "init" command. sam --version. SAM CLI, version 1.2.0.
Read more >
Resolve model validation failed errors in CloudFormation - AWS
When I create a resource with AWS CloudFormation, I receive a "Model Validation Failed" error in my stack events. Short description. Type, ...
Read more >
Properties validation failed for resource Error [pattern] - Cloud ...
Properties validation failed for resource lambda function with message #/Role: failed validation constraint for keyword [pattern].
Read more >
node deploy serverless AppLambdaFunction is returning an ...
Properties validation failed for resource AppLambdaFunction with message: #/Role: failed validation constraint for keyword [pattern].
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found