jsii
jsii copied to clipboard
TypeError: unhashable type: 'collections.OrderedDict' while looking up for existing ApiGateway
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 <module>
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
I recently ran into exactly the same problem trying to split a single Rest Api stack into microservices (multiple stacks). Any updates on this topic?
Very late comment but I have the same problem too.