The security token included in the request is invalid on cn-northwest-1
See original GitHub issueHow to reproduce the issue?
from moto import mock_lambda
import boto3
@mock_lambda
def test_china():
client = boto3.client("lambda", region_name="cn-northwest-1")
client.list_functions()
Will raise an exception:
@mock_lambda
def test_china():
client = boto3.client("lambda", region_name="cn-northwest-1")
> client.list_functions()
test_sts_service.py:20:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../venv/lib/python3.7/site-packages/botocore/client.py:357: in _api_call
return self._make_api_call(operation_name, kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <botocore.client.Lambda object at 0x111731490>
operation_name = 'ListFunctions', api_params = {}
def _make_api_call(self, operation_name, api_params):
operation_model = self._service_model.operation_model(operation_name)
service_name = self._service_model.service_name
history_recorder.record('API_CALL', {
'service': service_name,
'operation': operation_name,
'params': api_params,
})
if operation_model.deprecated:
logger.debug('Warning: %s.%s() is deprecated',
service_name, operation_name)
request_context = {
'client_region': self.meta.region_name,
'client_config': self.meta.config,
'has_streaming_input': operation_model.has_streaming_input,
'auth_type': operation_model.auth_type,
}
request_dict = self._convert_to_request_dict(
api_params, operation_model, context=request_context)
service_id = self._service_model.service_id.hyphenize()
handler, event_response = self.meta.events.emit_until_response(
'before-call.{service_id}.{operation_name}'.format(
service_id=service_id,
operation_name=operation_name),
model=operation_model, params=request_dict,
request_signer=self._request_signer, context=request_context)
if event_response is not None:
http, parsed_response = event_response
else:
http, parsed_response = self._make_request(
operation_model, request_dict, request_context)
self.meta.events.emit(
'after-call.{service_id}.{operation_name}'.format(
service_id=service_id,
operation_name=operation_name),
http_response=http, parsed=parsed_response,
model=operation_model, context=request_context
)
if http.status_code >= 300:
error_code = parsed_response.get("Error", {}).get("Code")
error_class = self.exceptions.from_code(error_code)
> raise error_class(parsed_response, operation_name)
E botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the ListFunctions operation: The security token included in the request is invalid.
../../../venv/lib/python3.7/site-packages/botocore/client.py:661: ClientError
On the other hand, when running in a different region, no exception is raised:
@mock_lambda
def test_us():
client = boto3.client("lambda", region_name="us-west-1")
client.list_functions()
This error happens in other services as well (e.g “sts”) and not only in the lambda service.
Versions: python==3.7 moto== 1.3.16 pytest==5.2.2 boto==2.49.0 botocore==1.12.189
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:9
Top Results From Across the Web
Resolve "The security token included in the request is expired ...
You must refresh the credentials before they expire. Another reason for expiration is using the incorrect time. A consistent and accurate time reference...
Read more >Serverless Error: The security token included in the request is ...
when i type serverless deploy appear this error: ServerlessError: The security token included in the request is invalid.
Read more >VNA AWS Plugin not collecting Flow Logs for NFA
Trying to integrate the AWS VPC for CA Network Flow Analysis (NFA) plugin with NFA via the DX NetOps Performance Management Portal.
Read more >Dynamic Secrets within China (cn-northwest-1) - AWS
Error: error checking if credentials are valid: InvalidClientTokenId: The security token included in the request is invalid.
Read more >How do I resolve the security token expired warning when ...
Randy shows you how to resolve “ The security token included in the request is expired” when running Java apps on EC2.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ll open this back up, there should be a way to fix this for all services without having to spell it out one by one
Get same error here, for kinesis client and in region eu-west-1