import { stringify } from "querystring" ; /** Parse properties of the ARN into an object */ interface Tags { account_id : string ; region : string ; functionname : string ; executedversion ? : string ; resource ? : string ; } export function parseLambdaARN ( arn , version ? ) { let region ; let account_id ; let functionname ; let alias ; const splitArn = arn . split ( ":" ) ; [ , , , region , account_id , , functionname , alias ] = splitArn ; const tags = { region , account_id , functionname } ; if ( alias !== undefined ) { if ( alias . startsWith ( "$" ) ) { alias = alias . substring ( 1 ) ; } else if ( ! Number ( alias ) ) { tags . executedversion = version ; } tags . resource = functionname + ":" + alias ; } else { tags . resource = functionname ; } return tags ; } param obj function makeTagStringsFromObject ( tags ) { return Object . entries ( tags ) . map ( ( [ tagKey , tagValue ] ) => `${ tagKey }:${ tagValue }` ) ; } /** Get the array of "key:value" string tags from the Lambda ARN */ export function parseTagsFromARN ( arn , version ? ) { return makeTagStringsFromObject ( parseLambdaARN ( arn , version ) ) ; }