Cannot set property 'S3Key' of undefined

aws

#1

Output of serverless deploy --debug w/ SLS_DEBUG=’*’

No idea what to look for. Any help would be appreciated.

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

Cannot set property ‘S3Key’ of undefined

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

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

TypeError: Cannot set property ‘S3Key’ of undefined
at _.forEach (/usr/local/lib/node_modules/serverless/lib/plugins/aws/lib/normalizeFiles.js:13:38)
at /usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:4944:15
at baseForOwn (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:3001:24)
at /usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:4913:18
at Function.forEach (/usr/local/lib/node_modules/serverless/node_modules/lodash/lodash.js:9359:14)
at Object.normalizeCloudFormationTemplate (/usr/local/lib/node_modules/serverless/lib/plugins/aws/lib/normalizeFiles.js:10:7)
at AwsDeploy.checkIfDeploymentIsNecessary (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/checkForChanges.js:89:45)
From previous event:
at AwsDeploy.checkForChanges (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/lib/checkForChanges.js:22:8)
From previous event:
at Object.aws:deploy:deploy:checkForChanges [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:102:10)
at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:360:55)
From previous event:
at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:360:22)
at PluginManager.spawn (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:378:17)
at AwsDeploy.BbPromise.bind.then (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:91:48)
From previous event:
at Object.deploy:deploy [as hook] (/usr/local/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:87:10)
at BbPromise.reduce (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:360:55)
From previous event:
at PluginManager.invoke (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:360:22)
at PluginManager.run (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:391:17)
at variables.populateService.then (/usr/local/lib/node_modules/serverless/lib/Serverless.js:99:33)
at runCallback (timers.js:666:20)
at tryOnImmediate (timers.js:639:5)
at processImmediate [as _immediateCallback] (timers.js:611:5)
From previous event:
at Serverless.run (/usr/local/lib/node_modules/serverless/lib/Serverless.js:86:74)
at serverless.init.then (/usr/local/lib/node_modules/serverless/bin/serverless:39:50)


#2

You wouldn’t happen to be listing one of your lambda functions under the resources section would you? Something like this:

resources:
  Resources:
    lambdaFnName:
      Type: AWS::Lambda::Function
      Properties:
        ...

It appears that if you add a lambda under the resources section, the Code field is required and the error handling for a missing Code field is pretty poor (as in non-existent).


#3

I encountered the same issue and it was because the case of the function name was off in the resources section. I renamed the lambda function name in the resources section to match the lambda function name exactly from .serverless/cloudformation-template-update-stack.json and the S3Key error went away.


#4

I think you forgot to add Code field in lambda function resource

resources:
Resources:
offlineStatemenFunction:
Type: AWS::Lambda::Function
Properties:
Code: #actual code, which echos the incoming event
ZipFile: >
exports.handler = function(event, context, callback) {
console.log(“receiving event”);
console.log(event);
callback(null,“done”);
};
Handler: index.handler
Role:
Fn::GetAtt: [ LambdaRole , ARN ]
Runtime: nodejs8.10
Timeout: 300
[/quote]


#5

The issue comes from the fact that sometimes there is a difference between how you name the function in your serverless.yaml file and how the framework actually names it during its creation in CloudFormation.

For instance, I named a function onObjectCreated in the configuration file, whereas it became OnObjectCreatedLambdaFunction in CloudFormation.

You can see this inspecting the list of created Resources in the console of the service.