def sig2(method, endpoint, params, provider, aws_api_version):
 timenow = datetime.utcnow()
 timestamp = timenow.strftime('%Y-%m-%dT%H:%M:%SZ')
 (access_key_id, secret_access_key, token) = creds(provider)
 params_with_headers = params.copy()
 params_with_headers['AWSAccessKeyId'] = access_key_id
 params_with_headers['SignatureVersion'] = '2'
 params_with_headers['SignatureMethod'] = 'HmacSHA256'
 params_with_headers['Timestamp'] = '{0}'.format(timestamp)
 params_with_headers['Version'] = aws_api_version
 keys = sorted(params_with_headers.keys())
 values = list(list(map(params_with_headers.get, keys)))
 querystring = urlencode(list(zip(keys, values)))
 canonical = '{0}\n{1}\n/\n{2}'.format(method.encode('utf-8'), endpoint.encode('utf-8'), querystring.encode('utf-8'))
 hashed = hmac.new(secret_access_key, canonical, hashlib.sha256)
 sig = binascii.b2a_base64(hashed.digest())
 params_with_headers['Signature'] = sig.strip()
 if (token != ''):
  params_with_headers['SecurityToken'] = token
 return params_with_headers

def sig2 ( method , endpoint , params , provider , aws_api_version ) : timenow = datetime . utcnow ( ) timestamp = timenow . strftime ( '%Y-%m-%dT%H:%M:%SZ' ) ( access_key_id , secret_access_key , token ) = creds ( provider ) params_with_headers = params . copy ( ) params_with_headers [ 'AWSAccessKeyId' ] = access_key_id params_with_headers [ 'SignatureVersion' ] = '2' params_with_headers [ 'SignatureMethod' ] = 'HmacSHA256' params_with_headers [ 'Timestamp' ] = '{0}' . format ( timestamp ) params_with_headers [ 'Version' ] = aws_api_version keys = sorted ( params_with_headers . keys ( ) ) values = list ( list ( map ( params_with_headers . get , keys ) ) ) querystring = urlencode ( list ( zip ( keys , values ) ) ) canonical = '{0}\n{1}\n/\n{2}' . format ( method . encode ( 'utf-8' ) , endpoint . encode ( 'utf-8' ) , querystring . encode ( 'utf-8' ) ) hashed = hmac . new ( secret_access_key , canonical , hashlib . sha256 ) sig = binascii . b2a_base64 ( hashed . digest ( ) ) params_with_headers [ 'Signature' ] = sig . strip ( ) if ( token != '' ) : params_with_headers [ 'SecurityToken' ] = token return params_with_headers
sign a query against aws services using signature version 2 signing process .