FUNCTION_ERROR_INIT_FAILURE AWS lambda - node.js

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

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)

Related

Deployment of simple node js application to AWS Lambda Serverless Failing with GeneralServiceException

I'm trying to deploy a simple NodeJS application to aws lambda serverless using aws cli. In the deployment the process, the application throws GeneralService Exception with the following error message.
Deploying aws-demo to stage dev (us-east-1)
Warning: Not authorized to perform: lambda:GetFunction for at least one of the lambda functions. Deployment will not be skipped even if service files did not change.
× Stack aws-demo-dev failed to deploy (155s)
Environment: win32, node 14.15.5, framework 3.26.0, plugin 6.2.2, SDK 4.3.2
Credentials: Local, "default" profile
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
CREATE_FAILED: HelloLambdaFunction (AWS::Lambda::Function)
Resource handler returned message: "null (Service: Lambda, Status Code: 403, Request ID: 0f60ffeb-add5-4571-856f-72a390ce5be9)" (RequestToken: beefe9c6-32d2-5d7f-f483-d97a6e76b73c, HandlerErrorCode: GeneralServiceException)
Below is the serverless.yml file configuration of the application:
service: aws-demo
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs12.x
memorySize: 512
stage: dev
timeout: 15
region: us-east-1
functions:
hello:
handler: handler.hello
events:
- http: ANY /{proxy+}
- http: ANY /
Upgrade your AWS user credentials!
Overwrite if its already done, using overwrite command.

Serverless deployed environment variables do not update

The app is a nodejs app deployed to AWS Lambda using Serverless. I have the production environment variables stored in .env-prod.json
serverless.yml:
custom:
stage: ${opt:stage, self:provider.stage}
service: my-backend
provider:
name: aws
runtime: nodejs14.x
stage: prod
region: us-east-1
memorySize: 128
functions:
app:
handler: index.handler
environment: ${file(./.env-${self:custom.stage}.json)}
events:
- http:
path: /
method: ANY
cors: true
- http:
path: /{proxy+}
method: ANY
cors: true
.env-prod.json:
{
"ENVIRONMENT": "prod",
"TEST1": "abc",
"TEST2": "abc2"
}
For the first serverless deploy I had only TEST1 var present and this deployed successfully. Now, after I added TEST2 var, then run serverless deploy, it does not deploy the new variable or any change to a variable, only code and code changes. In order to change or add a new var, I have to go to the AWS console UI and do it there.
Is there some special way to re-deploy the variables? I have tried the force option which had no effect.
I fixed this issue changing ${self:custom.stage} to ${opt:stage, self:provider.stage, 'dev'}
I hope it will work for your case. Tks

Serverless: Layers No file matches include / exclude patterns

My serverless.yml file works fine as soon as I add layers I starting getting this error
Serverless Error ----------------------------------------
No file matches include / exclude patterns
service: foundation
useDotenv: true
custom:
name: foundation
provider:
name: aws
stackName: ${self:service}-${self:provider.stage}
region: us-east-1
stage: ${opt:stage, 'dev'}
environment:
REGION: ${self:provider.region}
STAGE: ${self:provider.stage}
layers:
certificates:
path: certificate
plugins:
- serverless-deployment-bucket
- serverless-pseudo-parameters
- serverless-plugin-typescript
functions:
- ${file(./src/handler/function.yml)}
resources:
- ${file(./resources/outputs.yml)}
runtime: Node.js
Note: using layers to add certificates to lambda
Serverless version: 2.31.0
You may be getting this error if you execlude the directory where the layer is running through the plugins you use or in another part of the yml file. Maybe editing it this way will solve the problem
this link has an explanation about it
layers:
certificates:
package:
include:
- ./your/layer/path/**

Serverless deployment errorL Environment variable iamRoleStatements must contain string

I am trying to locally run serverless deploy but getting this error:
Serverless Error ---------------------------------------
Environment variable iamRoleStatements must contain string
Below is the relevant part from my serverless.yml
provider:
name: aws
runtime: nodejs10.x
stage: prod
region: us-east-1
environment:
tableName: profiles
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:DescribeTable
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: 'arn:aws:dynamodb:us-east-1:*:*'
Below is my environment information:
Your Environment Information ---------------------------
Operating System: darwin
Node Version: 12.16.1
Framework Version: 1.64.0
Plugin Version: 3.4.0
SDK Version: 2.3.0
Components Core Version: 1.1.2
Components CLI Version: 1.4.0
Any idea where I might be wrong?
Your iam roles seem to be configured correctly.
Double check your indentation on the roles are correct, at first I would say it's probably missing one space at least comparing the environment definitions
environment:
tableName: profiles
iamRoleStatements:
- Effect: Allow

Serverless not including my node_modules

I have a nodejs serverless project that has this structure:
-node_modules
-package.json
-serverless.yml
-funcitons
-medium
-mediumHandler.js
my serverless.yml:
service: googleAnalytic
provider:
name: aws
runtime: nodejs6.10
stage: dev
region: us-east-1
package:
include:
- node_modules/**
functions:
mediumHandler:
handler: functions/medium/mediumHandler.mediumHandler
events:
- schedule:
name: MediumSourceData
description: 'Captures data between set dates'
rate: rate(2 minutes)
- cloudwatchEvent:
event:
source:
- "Lambda"
detail-type:
- ""
- cloudwatchLog: '/aws/lambda/mediumHandler'
my sls info shows:
Service Information
service: googleAnalytic
stage: dev
region: us-east-1
stack: googleAnalytic-dev
api keys:
None
endpoints:
None
functions:
mediumHandler: googleAnalytic-dev-mediumHandler
When I run sls:
serverless invoke local -f mediumHandler
it works and my script where I included googleapis and aws-sdk work. But when I deploy, those functions are skipped and show no error.
When debugging serverless's packaging process, use sls package (or sls deploy --noDeploy (for old versions). You'll get a .serverless directory that you can inspect to see what's inside the deployment package.
From there, you can see if node_modules is included or not and make changes to your serverless.yml correspondingly without needing to deploy every time you make a change.
Serverless will exclude development packages by default. Check your package.json and ensure your required packages are in the dependencies object, as devDependencies will be excluded.
I was dumb to put this in my serverless.yml which caused me the same issue you're facing.
package:
patterns:
- '!node_modules/**'

Resources