Skip to content

Updated Cloudfront Proxy Event #2

Open
@siralpega

Description

@siralpega

AWS Cloudfront has a new version of their proxy event (v2), which is being treated as an APIGatewayProxyEventV2 event instead of a CloudFrontRequestEvent. It seems like the new version is almost identical to the API Gateway Event, except for the remoteAddress field. By changing the remoteAddress line in event-mapper.js, I was able to get the new Cloudfront event version working for my use case:

function convertFromAPIGatewayProxyEventV2(event) {
    const { rawPath, rawQueryString, requestContext } = event;
    return {
        type: "v2",
        method: requestContext.http.method,
        rawPath,
        url: rawPath + (rawQueryString ? `?${rawQueryString}` : ""),
        body: normalizeAPIGatewayProxyEventV2Body(event),
        headers: normalizeAPIGatewayProxyEventV2Headers(event),
        remoteAddress: event?.headers["x-forwarded-for"] ?? requestContext.http.sourceIp
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions