# eventSourceMapping kinesis-\>lambda

**URL:** <https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94>\
**Category:** Serverless Framework\
**Created:** [August 9, 2016, 1:41pm UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94 "2016-08-09T13:41:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sommero](https://avatars.discourse-cdn.com/v4/letter/s/898d66/32.png) [@sommero](https://forum.serverless.com/u/sommero)\
**Post date:** [August 9, 2016, 1:41pm UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94/1 "2016-08-09T13:41:09Z")

</div>

From the docs it should be possible to deploy an eventSourceMapping from kinesis to a lambda function.

this is my definition:

```auto
functions:
  myFunction:
    handler: org.example.MyJavaClass

resources:
  Resources:
    myKinesisStream:
      Type: AWS::Kinesis::Stream
      Properties:
        Name: myStreamInput
        ShardCount: 1
    myKinesisLambdaMapping:
      Type: AWS::Lambda::EventSourceMapping
      Properties:
        EventSourceArn:
          Fn::GetAtt:
            - "myKinesisStream"
            - "Arn"
        FunctionName:
          Fn::GetAtt:
            - "myFunction"
            - "Arn"
        StartingPosition: "TRIM_HORIZON"
        BatchSize: 10

```

the lambda function itself is ok and creates, the kinesis steam as well. just when I add the mapping it doesn’t work, as if the definition of the lambda function wasn’t known to the mapping factory, this error message is printed out:

```auto
# sls deploy
Serverless: Creating Stack...

  Validation Error ---------------------------------------

     Template error: instance of Fn::GetAtt references undefined
     resource myFunction

     For debugging logs, run again after setting SLS_DEBUG env var.

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

ValidationError: Template error: instance of Fn::GetAtt references undefined resource myFunction
    at Request.extractError (/home/oso/serverless/node_modules/aws-sdk/lib/protocol/query.js:40:29)
    at Request.callListeners (/home/oso/serverless/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
    at Request.emit (/home/oso/serverless/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/oso/serverless/node_modules/aws-sdk/lib/request.js:615:14)
    at Request.transition (/home/oso/serverless/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/oso/serverless/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/oso/serverless/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/oso/serverless/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/home/oso/serverless/node_modules/aws-sdk/lib/request.js:617:12)
    at Request.callListeners (/home/oso/serverless/node_modules/aws-sdk/lib/sequential_executor.js:115:18)
    at Request.emit (/home/oso/serverless/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
    at Request.emit (/home/oso/serverless/node_modules/aws-sdk/lib/request.js:615:14)
    at Request.transition (/home/oso/serverless/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/home/oso/serverless/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /home/oso/serverless/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/home/oso/serverless/node_modules/aws-sdk/lib/request.js:38:9)

```

I am pretty sure that I am missing just a small detail. Someone able to spot it?

The definition of the FunctionName seems to be the problematic part. AFAIK, the definition is created according to the documentation: [SLS about event source mapping](https://github.com/serverless/serverless/blob/master/docs/guide/overview-of-event-sources.md#kinesis-streams) and [AWS about event source mapping](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)

---

<div class="post-metadata">

**Author:** ![flomotlik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/flomotlik/32/3_2.png) [@flomotlik](https://forum.serverless.com/u/flomotlik)\
**Post date:** [August 10, 2016, 1:56pm UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94/2 "2016-08-10T13:56:09Z")

</div>

This can probably be fixed with a DependsOn setting: [http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html)

Otherwise the kinesis stream or the lambda function might not have been created, thus the mapping doesn’t work. Please also check the function logical name as it isn’t necessarily just myFunction

---

<div class="post-metadata">

**Author:** ![mikkelspring](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mikkelspring](https://forum.serverless.com/u/mikkelspring)\
**Post date:** [August 16, 2016, 4:23am UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94/3 "2016-08-16T04:23:35Z")

</div>

Can you please show an example configuration that works? I am trying to accomplish the exact same scenario and am stuck on the function name too – I also tried to use the full name of the lambda function as it is deployed on AWS but still no luck.

---

<div class="post-metadata">

**Author:** ![mikkelspring](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@mikkelspring](https://forum.serverless.com/u/mikkelspring)\
**Post date:** [August 16, 2016, 4:56am UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94/4 "2016-08-16T04:56:17Z")

</div>

OK I figured it out…there needs to be DependsOn and IAM role

EDIT: I was trying to setup another stream, which was failing on permissions for an indiscernible reason. It appears to be because I needed to include IamPolicyLambda in DependsOn

```
service: kinesis
provider:
  name: aws
  runtime: nodejs4.3
  iamRoleStatements:
      - Effect: "Allow"
         Action:
           - "kinesis:DescribeStream"
           - "kinesis:GetRecords"
           - "kinesis:GetShardIterator"
           - "kinesis:ListStreams"
           - "logs:CreateLogGroup"
           - "logs:CreateLogStream"
           - "logs:PutLogEvents"
         Resource: "*"

functions:
  hello:
    handler: handler.hello

resources:
  Resources:
    KinesisStream:
      Type: AWS::Kinesis::Stream
      Properties:
        Name: another-test-stream
        ShardCount: 1
    KinesisTestMap:
      Type: AWS::Lambda::EventSourceMapping
      DependsOn : 
        - "hello"
        - "IamPolicyLambda
      Properties:
        BatchSize: 10
        EventSourceArn:
          Fn::GetAtt:
            - "KinesisStream"
            - "Arn"
        FunctionName:
          Fn::GetAtt:
            - "hello"
            - "Arn"
        StartingPosition: "TRIM_HORIZON"
```

---

<div class="post-metadata">

**Author:** ![yeehaa123](https://avatars.discourse-cdn.com/v4/letter/y/a9adbd/32.png) [@yeehaa123](https://forum.serverless.com/u/yeehaa123)\
**Post date:** [September 16, 2016, 9:40pm UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94/5 "2016-09-16T21:40:25Z")

</div>

This solution does not work for me. Still get the same error as @mikkelspring. Any suggestions?

---

<div class="post-metadata">

**Author:** ![mikkelfish](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@mikkelfish](https://forum.serverless.com/u/mikkelfish)\
**Post date:** [October 5, 2016, 2:53am UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94/6 "2016-10-05T02:53:27Z")

</div>

Hey, @yeehaa123 sorry didn’t see this because I left the job I was at. It is still working for me: but I have noticed that in general things can fail until you have created the function separately. I tend to comment out all my resources, deploy and then uncomment them/deploy again.

Also, the variables have changed with Serverless RC1, so now I have

```auto
service: kinesis-test

provider:
  name: aws
  runtime: nodejs4.3
  stage: dev
  iamRoleStatements:
    - Effect: "Allow"
       Action:
         - "kinesis:DescribeStream"
         - "kinesis:GetRecords"
         - "kinesis:GetShardIterator"
         - "kinesis:ListStreams"
         - "logs:CreateLogGroup"
         - "logs:CreateLogStream"
         - "logs:PutLogEvents"
       Resource: "*"

custom:
  stage: ${opt:stage, self:provider.stage}

functions:
  test:
    handler: index.test
    memorySize: 128

resources:
  Resources:
    KinesisStream:
      Type: AWS::Kinesis::Stream
      Properties:
        Name: test-stream
        ShardCount: 1
    KinesisTestMap:
      Type: AWS::Lambda::EventSourceMapping
      DependsOn : 
        - "TestLambdaFunction"
        - "IamPolicyLambdaExecution"
      Properties:
        BatchSize: 10
        EventSourceArn:
          Fn::GetAtt:
            - "KinesisStream"
            - "Arn"
        FunctionName:
          Fn::GetAtt:
            - "TestLambdaFunction"
            - "Arn"
        StartingPosition: "TRIM_HORIZON"

```

---

<div class="post-metadata">

**Author:** ![ianserlin](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ianserlin/32/34_2.png) [@ianserlin](https://forum.serverless.com/u/ianserlin)\
**Post date:** [October 5, 2016, 4:39pm UTC](https://forum.serverless.com/t/eventsourcemapping-kinesis-lambda/94/7 "2016-10-05T16:39:40Z")

</div>

@yeeha123 If you are deploying with v1.0.0-rc1 or later it might be because the way the lambda functions are named in the auto-generated CloudFormation file have changed, so instead of every instance of `hello` in the `resources` section posted by @mikkelspring, you would need to replace it with `HelloLambdaFunction` as this is the name that Serverless gives the lambda `hello` in CloudFormation.

Cheers!

- Ian  
[useful.io](http://useful.io)
