Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using "DynamoEventSource" for a imported table on Python #6344

Closed
jpenalber opened this issue Feb 18, 2020 · 2 comments · Fixed by #6635
Closed

Error using "DynamoEventSource" for a imported table on Python #6344

jpenalber opened this issue Feb 18, 2020 · 2 comments · Fixed by #6635
Assignees
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB cause/python-no-types User mistakes caused by a lack of typing enforced by Python effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. wontfix We have determined that we will not resolve the issue.

Comments

@jpenalber
Copy link

When trying to create a DynamoDB source for my lambda there is some kind type conflict. I believe there is some kind of bug on the type error on handling the table since the return is an ITABLE

Reproduction Steps


table = aws_dynamodb.Table.from_table_attributes(self, "Name",table_name="<table-name>")

event = aws_lambda_event_sources.DynamoEventSource(table, starting_position=aws_lambda.StartingPosition.TRIM_HORIZON)

Error Log

jsii.errors.JavaScriptError: 
  Error: Object of type @aws-cdk/core.Resource is not convertible to @aws-cdk/aws-dynamodb.Table
      at Object.deserialize (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:6964:27)
      at Kernel._toSandbox (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8207:61)
      at xs.map (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8260:33)
      at Array.map (<anonymous>)
      at Kernel._boxUnboxParameters (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8260:19)
      at Kernel._toSandboxValues (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8245:21)
      at obj._wrapSandboxCode (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7838:66)
      at Kernel._wrapSandboxCode (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8301:19)
      at Kernel._create (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7838:26)
      at Kernel.create (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7585:21)
      at KernelHost.processRequest (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7372:28)
      at KernelHost.run (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7312:14)
      at Immediate.setImmediate [as _onImmediate] (/usr/local/lib/python3.6/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7315:37)
      at runCallback (timers.js:705:18)
      at tryOnImmediate (timers.js:676:5)
      at processImmediate (timers.js:658:5)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "app.py", line 9, in <module>
    WorkflowStackStack(app, "workflow-stack")
  File "/usr/local/lib/python3.6/site-packages/jsii/_runtime.py", line 66, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/home/ec2-user/environment/workflow-stack/workflow_stack/workflow_stack_stack.py", line 60, in __init__
    event = aws_lambda_event_sources.DynamoEventSource(table, starting_position=aws_lambda.StartingPosition.TRIM_HORIZON)
  File "/usr/local/lib/python3.6/site-packages/jsii/_runtime.py", line 66, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/aws_cdk/aws_lambda_event_sources/__init__.py", line 443, in __init__
    jsii.create(DynamoEventSource, self, [table, props])
  File "/usr/local/lib/python3.6/site-packages/jsii/_kernel/__init__.py", line 229, in create
    interfaces=[iface.__jsii_type__ for iface in getattr(klass, "__jsii_ifaces__", [])],
  File "/usr/local/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 333, in create
    return self._process.send(request, CreateResponse)
  File "/usr/local/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 318, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Object of type @aws-cdk/core.Resource is not convertible to @aws-cdk/aws-dynamodb.Table
Subprocess exited with error 1

Environment

  • CLI Version : aws-cli/1.17.17
  • Framework Version:1.24.0
  • OS :Amazon cloud9
  • Language :Python3.6

This is 🐛 Bug Report

@jpenalber jpenalber added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 18, 2020
@SomayaB SomayaB added the @aws-cdk/aws-dynamodb Related to Amazon DynamoDB label Feb 19, 2020
@SomayaB SomayaB added the jsii This issue originates in jsii, or this feature must be implemented in jsii. label Feb 19, 2020
@glitchedcat
Copy link

glitchedcat commented Mar 9, 2020

Can confirm this is an issue for me too.
Environment
CLI Version : aws-cli/1.17.11
Framework Version:1.27.0
OS : Macos Catalina
Language :Python3.7

RomainMuller added a commit that referenced this issue Mar 9, 2020
In order to make it possible to use the `DynamoEventSource` feature from
`@aws-cdk/aws-lambda-event-sources` with imported tables (`ITable`s
obtained from `Table.fromTableAttributes`), the `tableStreamArn`
property must be visible on the `ITable` interface, and accepted as part
of the `TableAttributes` struct.

The necessary `grant` methods that target the table stream were also
modified so that they can be used on any `ITable` that was built with a
`tableStreamArn`.

As a bonus, added documentation text for a couple of previously
undocumented enum constants.

Fixes #6344
@RomainMuller
Copy link
Contributor

The problem seems to be that DynamoEventSource's first parameters is typed as aws_dynamodb.Table, but the result of aws_dynamodb.Table.from_table_attributes is actually an aws_dynamodb.ITable.

So technically, your code is violating the type requirements for DynamoEventSource. Unfortunately, right now you get an error message that's not great (we are looking to improve this in aws/jsii#1321).

A secondary issue here is that you cannot currently use a "non-owned" (i.e: not created as part of the same CDK app) table with DynamoEventSource. That's arguably not a bug, but a feature gap... Regardless, I've prepared a PR to address this particular quirk at: #6635.

⚠️ Note however that in order to use this, you will need to provide the table_stream_arn property to from_table_attributes, as this is required in order to create the event source.

@RomainMuller RomainMuller added effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. and removed needs-triage This issue or PR still needs to be triaged. bug This issue is a bug. jsii This issue originates in jsii, or this feature must be implemented in jsii. labels Mar 9, 2020
@mergify mergify bot closed this as completed in #6635 Mar 9, 2020
mergify bot pushed a commit that referenced this issue Mar 9, 2020
In order to make it possible to use the `DynamoEventSource` feature from
`@aws-cdk/aws-lambda-event-sources` with imported tables (`ITable`s
obtained from `Table.fromTableAttributes`), the `tableStreamArn`
property must be visible on the `ITable` interface, and accepted as part
of the `TableAttributes` struct.

The necessary `grant` methods that target the table stream were also
modified so that they can be used on any `ITable` that was built with a
`tableStreamArn`.

As a bonus, added documentation text for a couple of previously
undocumented enum constants.

Fixes #6344
eladb pushed a commit that referenced this issue Mar 9, 2020
In order to make it possible to use the `DynamoEventSource` feature from
`@aws-cdk/aws-lambda-event-sources` with imported tables (`ITable`s
obtained from `Table.fromTableAttributes`), the `tableStreamArn`
property must be visible on the `ITable` interface, and accepted as part
of the `TableAttributes` struct.

The necessary `grant` methods that target the table stream were also
modified so that they can be used on any `ITable` that was built with a
`tableStreamArn`.

As a bonus, added documentation text for a couple of previously
undocumented enum constants.

Fixes #6344
horsmand pushed a commit to horsmand/aws-cdk that referenced this issue Mar 9, 2020
In order to make it possible to use the `DynamoEventSource` feature from
`@aws-cdk/aws-lambda-event-sources` with imported tables (`ITable`s
obtained from `Table.fromTableAttributes`), the `tableStreamArn`
property must be visible on the `ITable` interface, and accepted as part
of the `TableAttributes` struct.

The necessary `grant` methods that target the table stream were also
modified so that they can be used on any `ITable` that was built with a
`tableStreamArn`.

As a bonus, added documentation text for a couple of previously
undocumented enum constants.

Fixes aws#6344
@rix0rrr rix0rrr added the cause/python-no-types User mistakes caused by a lack of typing enforced by Python label Mar 20, 2020
@rix0rrr rix0rrr added the wontfix We have determined that we will not resolve the issue. label Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-dynamodb Related to Amazon DynamoDB cause/python-no-types User mistakes caused by a lack of typing enforced by Python effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. wontfix We have determined that we will not resolve the issue.
Projects
None yet
5 participants