Skip to main content

parse parameters

Project description

purus

Pytest codecov Code style: black Imports: isort Checked with mypy

PythonVersion PiPY

purus parses parameters provided from Lambda@Edge on CloudFront, and it manipulates request and response. It is named after The Purus River, or a tributary of The Amazon River.

Install

$ pip install purus

Usage

CloudFront:Lambda@Edge

purus can parse parameters of

  • viewer-request
  • origin-request
  • origin-response
  • viewer-response
# Lambda@Edge
from purus.amazon_cloudfront import CloudFrontLambdaEdge

# on viewer-request or origin-request
def lambda_handler(event: dict, _):
    # load data
    lambda_edge = CloudFrontLambdaEdge.from_event(event=event)
    
    # return on error
    if some_error_occurred:
        pseudo_payload = lambda_edge.add_pseudo_response(
            status="400",
            status_description="error_occurred"
        )
        return pseudo_payload.response.format()
    
    # redirect
    if redirect_condition:
        pseudo_payload = lambda_edge.add_pseudo_redirect_response(
            status="307",
            status_description="Redirect",
            location_url="https://redirect.example.com"
        )
        return pseudo_payload.response.format()
    
    # add headers to request
    modified_request = lambda_edge.append_request_header(
        key="X-Original-Header",
        value="Your data"
    ).append_request_header(
        key="X-Original-Header",
        value="Your additional data"
    )
    
    # to request
    return  modified_request.request.format()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

purus-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

purus-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file purus-0.1.1.tar.gz.

File metadata

  • Download URL: purus-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.13 Linux/5.15.0-1019-azure

File hashes

Hashes for purus-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f15124f1b104b5d93a1e0ef0ac4fdf64481eec5c05a8828ff794b35f85e535b
MD5 6ed3ccd640565e93d8e675286c06e411
BLAKE2b-256 6fec8650aa9566afe6a9bd189ce61df4be06b7ba29edd52e6955e97c6a9bf18e

See more details on using hashes here.

File details

Details for the file purus-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: purus-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.8.13 Linux/5.15.0-1019-azure

File hashes

Hashes for purus-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f57295ddfe4fd7c44694c61f7e590f21665bc01a5610bf43841b78f8c1935279
MD5 1614862c68d417f06e07392ce9fdcb1d
BLAKE2b-256 298ddbfd75bd414d47b645a407fb1b56be187f8b0eb8db3cd971055028e6794f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page