source/services/auth/index.js
// Send response to the pre-signed S3 URL
Send response to the pre-signed S3 URL
Send response to the pre - signed S3 URL
function sendResponse(event, context, responseStatus, responseData) {
    let responseBody = JSON.stringify({
        Status: responseStatus,
        Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName,
        PhysicalResourceId: context.logStreamName,
        StackId: event.StackId,
        RequestId: event.RequestId,
        LogicalResourceId: event.LogicalResourceId,
        Data: responseData
    });
    LOGGER.log('DEBUG',`RESPONSE BODY: ${JSON.stringify(responseBody,null,2)}`);
    let https = require("https");
    let url = require("url");
    let parsedUrl = url.parse(event.ResponseURL);
    let options = {
        hostname: parsedUrl.hostname,
        port: 443,
        path: parsedUrl.path,
        method: "PUT",
        headers: {
            "content-type": "",
            "content-length": responseBody.length
        }
    };
    LOGGER.log('DEBUG',"SENDING RESPONSE...\n");
    let request = https.request(options, function(response) {
        LOGGER.log('DEBUG',`STATUS: ${response.statusCode}`);
        LOGGER.log('DEBUG',`headers: ${JSON.stringify(response.headers)}`);
        context.done();
    });
    request.on("error", function(error) {
        LOGGER.log('ERROR',`sendResponse Error: ${error}`);
        context.done();
    });
    request.write(responseBody);
    request.end();
}
function sendResponse ( event , context , responseStatus , responseData ) { let responseBody = JSON . stringify ( { Status : responseStatus , Reason : "See the details in CloudWatch Log Stream: " + context . logStreamName , PhysicalResourceId : context . logStreamName , StackId : event . StackId , RequestId : event . RequestId , LogicalResourceId : event . LogicalResourceId , Data : responseData } ) ; LOGGER . log ( 'DEBUG' , ` ${ JSON . stringify ( responseBody , null , 2 ) } ` ) ; let https = require ( "https" ) ; let url = require ( "url" ) ; let parsedUrl = url . parse ( event . ResponseURL ) ; let options = { hostname : parsedUrl . hostname , port : 443 , path : parsedUrl . path , method : "PUT" , headers : { "content-type" : "" , "content-length" : responseBody . length } } ; LOGGER . log ( 'DEBUG' , "SENDING RESPONSE...\n" ) ; let request = https . request ( options , function ( response ) { LOGGER . log ( 'DEBUG' , ` ${ response . statusCode } ` ) ; LOGGER . log ( 'DEBUG' , ` ${ JSON . stringify ( response . headers ) } ` ) ; context . done ( ) ; } ) ; request . on ( "error" , function ( error ) { LOGGER . log ( 'ERROR' , ` ${ error } ` ) ; context . done ( ) ; } ) ; request . write ( responseBody ) ; request . end ( ) ; }
Send response to the pre-signed S3 URL
Send response to the pre - signed S3 URL
// Tell AWS Lambda that the function execution is done // Tell AWS Lambda that the function execution is done // write data to request body