AWS Rekognition detect_label is not working

0

I'm trying to detect images in my s3 bucket using AWS lambda and AWS rekognition. I was succedd with decect_faces code, and the code was able to successfully detect the faces in the images. But when I change it to detect_labels, it is giving me Access_denied exception. Here is the error: [ERROR] AccessDeniedException: An error occurred (AccessDeniedException) when calling the DetectLabels operation: Traceback (most recent call last):   File "/var/lang/lib/python3.11/importlib/init.py", line 126, in import_module     return _bootstrap._gcd_import(name[level:], package, level)   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked   File "<frozen importlib._bootstrap_external>", line 940, in exec_module   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed   File "/var/task/lambda_function.py", line 5, in <module>     response = rekognition.detect_labels(   File "/var/lang/lib/python3.11/site-packages/botocore/client.py", line 534, in _api_call     return self._make_api_call(operation_name, kwargs)   File "/var/lang/lib/python3.11/site-packages/botocore/client.py", line 976, in _make_api_call     raise error_class(parsed_response, operation_name)INIT_REPORT Init Duration: 507.29 ms Phase: init Status: error Error Type: Runtime.ExitError INIT_REPORT Init Duration: 3004.12 ms Phase: invoke Status: error Error Type: Runtime.Unknown START RequestId: 957a7b2b-94a7-4298-9ef6-049c68a49a57 Version: $LATEST 2023-11-20T02:16:49.421Z 957a7b2b-94a7-4298-9ef6-049c68a49a57 Task timed out after 3.05 seconds

END RequestId: 957a7b2b-94a7-4298-9ef6-049c68a49a57 REPORT RequestId: 957a7b2b-94a7-4298-9ef6-049c68a49a57 Duration: 3045.96 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 25 MB

Note: The lambda role was given all the necessary permissions according to the AWS documentation. Can someone please help. Thanks in advance

2 Answers
0

I think the important part of the error message is this:

Task timed out after 3.05 seconds

Try increasing the timeout on the Lambda function - the default is three seconds but you probably want it to run for longer than that.

profile pictureAWS
EXPERT
answered 5 months ago
  • Hey @brettski,

    Thank you for the quick response. I did try that earlier, it didn't work out. Here the error when the timeout is increased.

    Test Event Name 123

    Response { "errorMessage": "An error occurred (AccessDeniedException) when calling the DetectLabels operation: ", "errorType": "AccessDeniedException", "requestId": "", "stackTrace": [ " File "/var/lang/lib/python3.11/importlib/init.py", line 126, in import_module\n return _bootstrap._gcd_import(name[level:], package, level)\n", " File "<frozen importlib._bootstrap>", line 1204, in _gcd_import\n", " File "<frozen importlib._bootstrap>", line 1176, in _find_and_load\n", " File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked\n", " File "<frozen importlib._bootstrap>", line 690, in _load_unlocked\n", " File "<frozen importlib._bootstrap_external>", line 940, in exec_module\n", " File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed\n", " File "/var/task/lambda_function.py", line 5, in <module>\n response = rekognition.detect_labels(\n", " File "/var/lang/lib/python3.11/site-packages/botocore/client.py", line 534, in _api_call\n return self._make_api_call(operation_name, kwargs)\n", " File "/var/lang/lib/python3.11/site-packages/botocore/client.py", line 976, in _make_api_call\n raise error_class(parsed_response, operation_name)\n" ] }

    Function Logs [ERROR] AccessDeniedException:

  • You've mentioned that the Lambda function has the correct permissions; but the error message says that it doesn't. Try temporarily setting the policy action to (say) rekognition:* and the resource to * as well. If that works, figure out which permission was missing.

  • Hey @brettski-AWS, Thank you for the continuous support. In terms of permission I tried every possible solution. The one you mentioned above, Adding an inline policy according to the AWS documentation. Still not working. I'm getting the same error.

  • Are you operating in an Organization? Could there be a Service Control Policy blocking that action?

  • Nope, I'm working on my personal account. I'm literally struck here, followed everything according to the documentation, checked everywhere across web. I'm not able to find a solution for this.

0

@brettski AWS Reko policy

Rav
answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions