@@ -77,19 +77,42 @@ export function resetRunnersCaches() {
7777
7878export async function findAmiID ( metrics : Metrics , region : string , filter : string , owners = 'amazon' ) : Promise < string > {
7979 const ec2 = new EC2 ( { region : region } ) ;
80+ // Check if filter contains separator '|' and extract image name and account ID
81+ let imageName = filter ;
82+ let actualOwners = owners ;
83+
84+ if ( filter . includes ( '|' ) ) {
85+ const parts = filter . split ( '|' ) ;
86+ if ( parts . length === 2 ) {
87+ imageName = parts [ 0 ] . trim ( ) ;
88+ const extractedOwner = parts [ 1 ] . trim ( ) ;
89+
90+ // Check if the extracted owner is only numbers (AWS account ID format)
91+ if ( / ^ \d + $ / . test ( extractedOwner ) ) {
92+ actualOwners = extractedOwner ;
93+ } else {
94+ console . error (
95+ `Invalid account ID format: '${ extractedOwner } '. Account ID must` +
96+ ` contain only numbers. Using default value '${ actualOwners } '` ,
97+ ) ;
98+ }
99+ }
100+ }
101+
80102 const filters = [
81- { Name : 'name' , Values : [ filter ] } ,
103+ { Name : 'name' , Values : [ imageName ] } ,
82104 { Name : 'state' , Values : [ 'available' ] } ,
83105 ] ;
84- return redisCached ( 'awsEC2' , `findAmiID-${ region } -${ filter } -${ owners } ` , 10 * 60 , 0.5 , ( ) => {
106+
107+ return redisCached ( 'awsEC2' , `findAmiID-${ region } -${ imageName } -${ actualOwners } ` , 10 * 60 , 0.5 , ( ) => {
85108 return expBackOff ( ( ) => {
86109 return metrics . trackRequestRegion (
87110 region ,
88111 metrics . ec2DescribeImagesSuccess ,
89112 metrics . ec2DescribeImagesFailure ,
90113 ( ) => {
91114 return ec2
92- . describeImages ( { Owners : [ owners ] , Filters : filters } )
115+ . describeImages ( { Owners : [ actualOwners ] , Filters : filters } )
93116 . promise ( )
94117 . then ( ( data : EC2 . DescribeImagesResult ) => {
95118 /* istanbul ignore next */
0 commit comments