21

I recently added the cool lambda feature - provisioned concurrency.

After a few successful deployments, I now face this issue

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

ServerlessError: An error occurred: GraphqlPrivateProvConcLambdaAlias - Provisioned Concurrency configuration failed to be applied. Reason: FUNCTION_ERROR_INIT_FAILURE. at C:\Users\theod\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\lib\monitorStack.js:125:33 From previous event: at AwsDeploy.monitorStack (C:\Users\theod\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\lib\monitorStack.js:28:12) at C:\Users\theod\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\lib\updateStack.js:107:28 From previous event: at AwsDeploy.update

here's my sample serverless.yml file

service: backend-api

parameters:
  region: ap-southeast-2
  path: &path /

provider:
  name: aws
  runtime: nodejs12.x
  stage: ${env:STAGE, 'staging'}
  region: ap-southeast-2
  versionFunctions: true

plugins:
  - serverless-webpack
  - serverless-pseudo-parameters
  - serverless-prune-plugin
  # - serverless-offline-scheduler
  - serverless-offline

functions:
  # GRAPHQL APIs
  graphqlPrivate:
    handler: src/graphql/private/index.handler
    memorySize: 256
    timeout: 30
    name: ${self:service}-gqlPrivate-${self:provider.stage}
    vpc: ${file(./serverless/vpc.yml)}
    events:
        - http:
            path: /graphql/private
            method: ANY
            cors: true
            authorizer:
              arn: arn:aws:cognito-idp:#{AWS::Region}:#{AWS::AccountId}:userpool/${self:custom.cognitoArns.private.${self:provider.stage}}
    provisionedConcurrency: 10


package:
  individually: true

custom:
  webpack:
    keepOutputDirectory: true
    serializedCompile: true
    webpackConfig: 'webpack.config.js'
    packager: 'npm'
  stage: ${opt:stage, self:provider.stage}

  prune:
    automatic: true
    number: 1

anybody able to resolve this issue?

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              12.11.0
     Framework Version:         1.61.3
     Plugin Version:            3.2.7
     SDK Version:               2.3.0
     Components Core Version:   1.1.2
     Components CLI Version:    1.4.0
Theo
  • 1,932
  • 4
  • 17
  • 40

1 Answers1

40

FUNCTION_ERROR_INIT_FAILURE plainly means there's something wrong with the function's handler/code that i'm trying to deploy, w/c is why provisioned lambdas can't start up/initialize.

The way to resolve this, is to test w/o provisioned concurrency option first. Once you are able to push your lambda, error(s) will surely flow into your CW logs. The best way though, is to test your lambda locally(using serverless-offline plugin or serverless invoke), if it works properly. You can also package your app, and invoke it with serverless cli to detect issues on packaging.

In my case, there is a runtime error where my code bundle is looking for a require that is not part of bundle.

This is undocumented on AWS lambda as of now(Jan 29, 2020)

Theo
  • 1,932
  • 4
  • 17
  • 40
  • 1
    I have a case when invoking lambda function is working, but provisioned failed during init. What should have I do in this case? – Daniil Volkov Nov 06 '20 at 13:54
  • @DaniilVolkov you might be invoking an outdated lambda, because failing of provisioned lambda with error above is on deployment phase. Meaning your latest lambda failed to deploy successfully. So you should try to solve the issue first. Invoke might work locally, but it's a different story when you deploy because your code could be messed up on packaging, and you have to consider the things that might go wrong on production environment like missing ENV variables, missing lambda permissions, etc – Theo Nov 06 '20 at 14:40
  • I also find this error urges me to write unit/integrate test, since the wait time for the entire deployment process is so long that if it's a code syntax error it's just a huge penalty on development time. – Shawn Apr 01 '21 at 00:02
  • @ShaungCheng right. will be very cool to catch errors quickly/asap to overcome dev time penalty - via automations – Theo Apr 01 '21 at 10:14
  • For me I was missing an IAM Role... The lambda could not get a secret – rjdkolb Nov 11 '22 at 12:48
  • thanks for your answer, indeed, it worked; because there was some error in my code, after removing the lib and it worked, and it sometime complained about the concurrencye settings.... – Frank Guo Nov 27 '22 at 15:31