aws / aws/jsii

TypeError: unhashable type: 'collections.OrderedDict' while looking up for existing ApiGateway

Open
#3,932 2 comments 0 reactions 0 assignees View on GitHub
jsii p1 package/tools
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the issue

I have 2 stacks for example stack1 and stack2 .

in stack1 I have created api gateway with multiple resources and finally did this to export resources

```
cdk.CfnOutput(self, "api-export", export_name = 'api-id', value=stack1_api.rest_api_id)
cdk.CfnOutput(self, "resource-api-export", export_name='resource-api-id',value=stack1_api.rest_api_root_resource_id)
```
**and in importing in stack2**

```
from aws_cdk.aws_apigateway import RestApi

my_new_api = RestApi.from_rest_api_attributes(
self, "new-resource",
rest_api_id=cdk.Fn.import_value('api-id'),
root_resource_id=cdk.Fn.import_value('resource-api-id')
)
```

which is returning object . and finally adding new resource to it like this

```

mini_sets = my_new_api.root.add_resource("minibars")
mini_sets.add_method(
http_method='GET',
authorizer=minibar_sets_api_authorizer
)

```

and ran command to build **sam-beta-cdk build -p** which result as successful
and after that run command **sam-beta-cdk local start-api** which result into this error full trace-back :

```
File "samcli/__main__.py", line 12, in
File "click/core.py", line 829, in __call__
File "click/core.py", line 782, in main
File "click/core.py", line 1259, in invoke
File "click/core.py", line 1259, in invoke
File "click/core.py", line 1066, in invoke
File "click/core.py", line 610, in invoke
File "samcli/lib/iac/utils/helpers.py", line 55, in wrapper
File "samcli/commands/_utils/iac_validations.py", line 79, in wrapped
File "click/decorators.py", line 73, in new_func
File "click/core.py", line 610, in invoke
File "samcli/lib/telemetry/metric.py", line 174, in wrapped
File "samcli/lib/telemetry/metric.py", line 141, in wrapped
File "samcli/lib/utils/version_checker.py", line 42, in wrapped
File "samcli/cli/main.py", line 90, in wrapper
File "samcli/commands/local/start_api/cli.py", line 128, in cli
File "samcli/commands/local/start_api/cli.py", line 204, in do_cli
File "samcli/commands/local/lib/local_api_service.py", line 37, in __init__
File "samcli/lib/providers/api_provider.py", line 37, in __init__
File "samcli/lib/providers/api_provider.py", line 64, in _extract_api
File "samcli/lib/providers/cfn_api_provider.py", line 64, in extract_resources
File "samcli/lib/providers/cfn_api_provider.py", line 188, in _extract_cloud_formation_method
File "samcli/lib/providers/cfn_api_provider.py", line 351, in resolve_resource_path
File "/usr/local/lib/python3.7/_collections_abc.py", line 660, in get
File "samcli/lib/iac/interface.py", line 469, in __getitem__
TypeError: unhashable type: 'collections.OrderedDict'
[45088] Failed to execute script __main__
```

### Links

using from_rest_api_attributes function from https://docs.aws.amazon.com/cdk/api/v1/python/aws_cdk.aws_apigateway/README.html#breaking-up-methods-and-resources-across-stacks

Contributor guide

Open the contributing guide

Research direction

Reproduce the two-stack example with `sam-beta-cdk build -p` and `sam-beta-cdk local start-api`, then start at `samcli/lib/providers/cfn_api_provider.py`, especially `extract_resources`, `_extract_cloud_formation_method`, and `resolve_resource_path`. Trace the value reaching `samcli/lib/iac/interface.py` line 469 and confirm that the command completes without the OrderedDict TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
api, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.