marcodaniels / elm-aws-cloudfront / CloudFront.Lambda

Edge

Handlers

originRequest : (OriginRequest -> flags -> OutputEvent) -> flags -> Maybe InputOrigin -> OutputEvent

Handler for origin request events

originRequest
    (\{ request } flags ->
        { request | uri = "new-uri" }
            |> toRequest
    )

originResponse : (OriginResponse -> flags -> OutputEvent) -> flags -> Maybe InputOrigin -> OutputEvent

Handler for origin response events

originResponse
    (\{ response, request } _ ->
        response
            |> withHeader
                { key = "cache-control", value = "public, max-age=31536000" }
            |> toResponse
    )

Output

toRequest : Request -> OutputEvent

Map request to output event, to be used with originRequest or originResponse

toResponse : Response -> OutputEvent

Map response to output event, to be used with originResponse

Types

Types for the lambda event structure.


type alias InputEvent =
{ records : List Record }


type alias Record =
{ cf : InputOrigin }


type InputOrigin
    = InputResponse OriginResponse
    | InputRequest OriginRequest


type alias OriginResponse =
{ config : Config
, request : Request
, response : Response 
}


type alias OriginRequest =
{ config : Config
, request : Request 
}


type alias Config =
{ distributionDomainName : String
, distributionId : String
, eventType : String
, requestId : String 
}


type alias Request =
{ clientIp : String
, headers : CloudFront.Header.Headers
, method : String
, origin : Origin
, querystring : Maybe String
, uri : String 
}


type alias Response =
{ status : String
, statusDescription : String
, headers : CloudFront.Header.Headers 
}


type Origin
    = OriginS3 S3Origin
    | OriginCustom CustomOrigin
    | OriginUnknown


type alias S3Origin =
{ s3 : S3OriginData }


type alias S3OriginData =
{ authMethod : String
, customHeaders : CloudFront.Header.Headers
, domainName : String
, path : String
, region : String 
}


type alias CustomOrigin =
{ custom : CustomOriginData }


type alias CustomOriginData =
{ customHeaders : CloudFront.Header.Headers
, domainName : String
, keepaliveTimeout : Basics.Int
, path : String
, port_ : Basics.Int
, protocol : String
, readTimeout : Basics.Int
, sslProtocols : List String 
}


type OutputEvent
    = OutputResponse Response
    | OutputRequest Request