I wrote lambda function, that publishes message to topic via sns. I'd like to make integration tests with it, so localstack seems to be great solution.
On setup_class method I created lambda sucessfully, with zipped code and dependencies, also created sns topic, where I want to publish messages later in test.
In invoke lambda phase I'm getting error:
E REPORT RequestId: f9f3bac1-3b4b-4826-a5cb-362355087929 Duration: 1906 ms Billed Duration: 2000 ms Memory Size: 1536 MB Max Memory Used: 32 MB Traceback (most recent call last):
E File "/opt/code/localstack/localstack/services/awslambda/lambda_api.py", line 338, in run_lambda
E event, context=context, version=version, asynchronous=asynchronous)
E File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 81, in execute
E return do_execute()
E File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 66, in do_execute
E result, log_output = self._execute(func_arn, func_details, event, context, version)
E File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 230, in _execute
E result, log_output = self.run_lambda_executor(cmd, stdin, environment)
E File "/opt/code/localstack/localstack/services/awslambda/lambda_executors.py", line 151, in run_lambda_executor
E (return_code, log_output))
E Exception: Lambda process returned error status code: 1. Output:
E START RequestId: f9f3bac1-3b4b-4826-a5cb-362355087929 Version: $LATEST
E An error occurred (InvalidClientTokenId) when calling the Publish operation: The security token included in the request is invalid.: ClientError
E Traceback (most recent call last):
E File "/var/task/functions/opt_in.py", line 32, in handler
E MessageStructure='json'
E File "/var/task/botocore/client.py", line 357, in _api_call
E return self._make_api_call(operation_name, kwargs)
E File "/var/task/botocore/client.py", line 661, in _make_api_call
E raise error_class(parsed_response, operation_name)
E botocore.exceptions.ClientError: An error occurred (InvalidClientTokenId) when calling the Publish operation: The security token included in the request is invalid.
E
E END RequestId: f9f3bac1-3b4b-4826-a5cb-362355087929
E REPORT RequestId: f9f3bac1-3b4b-4826-a5cb-362355087929 Duration: 1906 ms Billed Duration: 2000 ms Memory Size: 1536 MB Max Memory Used: 32 MB
It says I have some issues with IAM maybe or roles, but during setup phase any actions as create lambda, create topic were run with no errors.
I've tried to add endpoint url for sns client in lambda function, but inside localstack it raises error "wrong url" (localstack enpoint for sns was 'http://localhost:4575').
How to solve "botocore.exceptions.ClientError" with localstack testing?