@@ -21,12 +21,12 @@ function getObjectPrefix(event: CloudformationEvent): string | undefined {
2121function validateArguments ( event : CloudformationEvent ) : void {
2222 const bucketName = getNewBucketName ( event ) ;
2323 if ( ! bucketName ) {
24- throw `${ CustomParameters . BUCKET_NAME } must be specified.` ;
24+ throw new Error ( `${ CustomParameters . BUCKET_NAME } must be specified.` ) ;
2525 }
2626}
2727
2828function computePhysicalId ( event : CloudformationEvent ) : string {
29- return `Bucket:${ getNewBucketName ( event ) } ObjectPrefix: ${ getObjectPrefix ( event ) } ` ;
29+ return `Bucket: ${ getNewBucketName ( event ) } ObjectPrefix: ${ getObjectPrefix ( event ) } ` ;
3030}
3131
3232// Send response to the pre-signed S3 URL
@@ -35,7 +35,7 @@ async function sendResponse(
3535 context : CloudformationContext ,
3636 responseStatus : ResponseStatus ,
3737 responseReason ?: string ,
38- responseData ?: object
38+ responseData ?: Record < string , unknown >
3939) : Promise < void > {
4040 const responseBody = JSON . stringify ( {
4141 Status : responseStatus ,
@@ -63,16 +63,16 @@ async function sendResponse(
6363
6464 console . log ( "SENDING RESPONSE...\n" ) ;
6565
66- await new Promise ( ( resolve , reject ) => {
66+ await new Promise < void > ( ( resolve , reject ) => {
6767 const request = https . request ( options , function ( response ) {
68- console . log ( " STATUS: " + response . statusCode ) ;
69- console . log ( " HEADERS: " + JSON . stringify ( response . headers ) ) ;
68+ console . log ( ` STATUS: ${ response . statusCode } ` ) ;
69+ console . log ( ` HEADERS: ${ JSON . stringify ( response . headers ) } ` ) ;
7070 // Tell AWS Lambda that the function execution is done
7171 resolve ( ) ;
7272 } ) ;
7373
7474 request . on ( "error" , function ( error ) {
75- console . log ( "sendResponse Error:" + error ) ;
75+ console . log ( "sendResponse Error: " , error ) ;
7676 // Tell AWS Lambda that the function execution is done
7777 reject ( ) ;
7878 } ) ;
@@ -84,10 +84,7 @@ async function sendResponse(
8484 } ) ;
8585}
8686
87- exports . handler = async function (
88- event : CloudformationEvent ,
89- context : CloudformationContext
90- ) : Promise < void > {
87+ async function handler ( event : CloudformationEvent , context : CloudformationContext ) : Promise < void > {
9188 console . log ( "REQUEST RECEIVED:\n" + JSON . stringify ( event ) ) ;
9289
9390 const callback : ResultCallback = async ( result : ResultType ) => {
@@ -96,10 +93,10 @@ exports.handler = async function (
9693
9794 try {
9895 validateArguments ( event ) ;
99- } catch ( errorMessage ) {
96+ } catch ( e ) {
10097 return await callback ( {
10198 status : ResponseStatus . FAILED ,
102- reason : errorMessage ,
99+ reason : ( e as Error ) . toString ( ) ,
103100 } ) ;
104101 }
105102
@@ -113,7 +110,10 @@ exports.handler = async function (
113110 default :
114111 return await callback ( {
115112 status : ResponseStatus . FAILED ,
116- reason : `Unknown request type ${ event . RequestType } ` ,
113+ reason : `Unknown request type ${ event . RequestType as string } ` ,
117114 } ) ;
118115 }
119- } ;
116+ }
117+
118+ declare const exports : Record < string , unknown > ;
119+ exports . handler = handler ;
0 commit comments