def invoke(cls, **kwargs):
"""Mocked invoke function that returns a reponse mimicking boto3's reponse
Keyword Arguments:
FuncitonName (str): The AWS Lambda function name being invoked
InvocationType (str): Type of invocation (typically 'Event')
Payload (str): Payload in string or file format to send to lambda
Qualifier (str): Alias for fully qualified AWS ARN
Returns:
dict: Response dictionary containing a fake RequestId
"""
if cls._raise_exception:
# Turn of the raise exception boolean so we don't do this next time
cls._raise_exception = not cls._raise_exception
err = {'Error': {'Code': 400, 'Message': 'raising test exception'}}
raise ClientError(err, 'invoke')
req_keywords = {'FunctionName', 'InvocationType', 'Payload'}
key_diff = req_keywords.difference(set(kwargs))
if key_diff:
message = 'required keyword missing: {}'.format(', '.join(key_diff))
err = {'Error': {'Code': 400, 'Message': message}}
raise ClientError(err, 'invoke')
if not isinstance(kwargs['Payload'], (str, bytearray)):
if not hasattr(kwargs['Payload'], 'read'):
err = ('Invalid type for parameter Payload, value: {}, type: {}, '
'valid types: <type \'str\'>, <type \'bytearray\'>, '
'file-like object').format(kwargs['Payload'], type(kwargs['Payload']))
raise ParamValidationError(response=err)
return {'ResponseMetadata': {'RequestId': '9af88643-7b3c-43cd-baae-addb73bb4d27'}}
评论列表
文章目录