# Cannot set property 'S3Key' of undefined

**URL:** <https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [November 14, 2017, 3:35pm UTC](https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102 "2017-11-14T15:35:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![efenderbosch](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/efenderbosch/32/1269_2.png) [@efenderbosch](https://forum.serverless.com/u/efenderbosch)\
**Post date:** [November 14, 2017, 3:35pm UTC](https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102/1 "2017-11-14T15:35:43Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![trevorhreed](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@trevorhreed](https://forum.serverless.com/u/trevorhreed)\
**Post date:** [January 11, 2018, 9:51pm UTC](https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102/2 "2018-01-11T21:51:27Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![brettcooper](https://avatars.discourse-cdn.com/v4/letter/b/e480ec/32.png) [@brettcooper](https://forum.serverless.com/u/brettcooper)\
**Post date:** [May 30, 2018, 3:34pm UTC](https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102/3 "2018-05-30T15:34:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![imrajdas](https://avatars.discourse-cdn.com/v4/letter/i/ed655f/32.png) [@imrajdas](https://forum.serverless.com/u/imrajdas)\
**Post date:** [August 7, 2018, 5:53pm UTC](https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102/4 "2018-08-07T17:53:36Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![kalinchernev](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/kalinchernev/32/1041_2.png) [@kalinchernev](https://forum.serverless.com/u/kalinchernev)\
**Post date:** [October 19, 2018, 7:42am UTC](https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102/5 "2018-10-19T07:42:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aljaz-S](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@Aljaz-S](https://forum.serverless.com/u/Aljaz-S)\
**Post date:** [February 25, 2020, 12:32pm UTC](https://forum.serverless.com/t/cannot-set-property-s3key-of-undefined/3102/6 "2020-02-25T12:32:14Z")

</div>

Hi, I am having same problem at the moment when I am trying to deploy from one AWS account to another. Would it be possible to provide your serverless.yaml file ?

At the moment I am not sure if the issue is with function name as it is mentioned in this topic or something else.

Thanks in advance.  
Br, Aljaž.
