serverless / examples

Serverless Examples – A collection of boilerplates and examples of serverless architectures built with the Serverless Framework on AWS Lambda, Microsoft Azure, Google Cloud Functions, and more.
https://www.serverless.com/examples/
Other
11.45k stars 4.47k forks source link

A quick fix on configuring local DynamoDB #660

Closed kywch closed 3 years ago

kywch commented 3 years ago
kywch commented 3 years ago

Opps, forgot to actually edit app.py

pgrzesik commented 3 years ago

Could you please share the reasoning behind the fix? I remember testing the setup and it worked correctly without these dummy access/secret keys passed explicitly

kywch commented 3 years ago

I added if-else to fix the below NoRegionError() problem. I didn't put the AWS credentials as environment variables.

Oh, and you are right! The code works without these dummy access/secret keys passed explicitly.

Thanks!

$ serverless wsgi serve
(node:95387) ExperimentalWarning: queueMicrotask() is experimental.
Serverless: Using Python specified in "runtime": python3.8
Traceback (most recent call last):
  File "/home/kywch/workspace/todo-camp-app/node_modules/serverless-wsgi/serve.py", line 82, in <module>
    serve(
  File "/home/kywch/workspace/todo-camp-app/node_modules/serverless-wsgi/serve.py", line 52, in serve
    wsgi_module = importlib.import_module(wsgi_fqn_parts[-1])
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/kywch/workspace/todo-camp-app/app.py", line 8, in <module>
    dynamodb_client = boto3.client('dynamodb')
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/boto3/__init__.py", line 93, in client
    return _get_default_session().client(*args, **kwargs)
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/boto3/session.py", line 270, in client
    return self._session.create_client(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/session.py", line 841, in create_client
    client = client_creator.create_client(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/client.py", line 88, in create_client
    client_args = self._get_client_args(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/client.py", line 357, in _get_client_args
    return args_creator.get_client_args(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/args.py", line 71, in get_client_args
    final_args = self.compute_client_args(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/args.py", line 148, in compute_client_args
    endpoint_config = self._compute_endpoint_config(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/args.py", line 220, in _compute_endpoint_config
    return self._resolve_endpoint(**resolve_endpoint_kwargs)
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/args.py", line 302, in _resolve_endpoint
    return endpoint_bridge.resolve(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/client.py", line 432, in resolve
    resolved = self.endpoint_resolver.construct_endpoint(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/regions.py", line 142, in construct_endpoint
    result = self._endpoint_for_partition(
  File "/home/kywch/workspace/todo-camp-app/.venv/lib/python3.8/site-packages/botocore/regions.py", line 167, in _endpoint_for_partition
    raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.