Skip to content

Windows AMI: Add possibility to use different owners specified in the filter param #7004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/scripts/validate_scale_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
"additionalProperties": False,
"properties": {
"ami_experiment": {"type": "object"},
"ami": {"type": "string"},
"ami": {
"type": "string",
"pattern": "^[A-Za-z0-9 -_. ]+(\|[0-9]+)?$",
"description": "AMI Name|AWS Account (optional).",
},
"disk_size": {"type": "number"},
"instance_type": {"type": "string"},
"is_ephemeral": {"type": "boolean"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,25 @@ describe('findAmiID', () => {
await findAmiID(metrics, 'REGION', 'FILTER2');
expect(mockEC2.describeImages).toBeCalledTimes(3);
});

it('handles filter with separator and custom account ID', async () => {
const result = await findAmiID(metrics, 'REGION', 'my-image|123456789012');
expect(mockEC2.describeImages).toBeCalledTimes(1);
expect(mockEC2.describeImages).toBeCalledWith({
Owners: ['123456789012'],
Filters: [
{
Name: 'name',
Values: ['my-image'],
},
{
Name: 'state',
Values: ['available'],
},
],
});
expect(result).toBe('ami-AGDGADU113');
});
});

describe('tryReuseRunner', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,42 @@ export function resetRunnersCaches() {

export async function findAmiID(metrics: Metrics, region: string, filter: string, owners = 'amazon'): Promise<string> {
const ec2 = new EC2({ region: region });
// Check if filter contains separator '|' and extract image name and account ID
let imageName = filter;
let actualOwners = owners;

if (filter.includes('|')) {
const parts = filter.split('|');
if (parts.length === 2) {
imageName = parts[0].trim();
const extractedOwner = parts[1].trim();

// Check if the extracted owner is only numbers (AWS account ID format)
if (/^\d+$/.test(extractedOwner)) {
actualOwners = extractedOwner;
} else {
console.error(
`Invalid account ID format: '${extractedOwner}'. Account ID must` +
` contain only numbers. Using default value '${actualOwners}'`,
);
}
}
}

const filters = [
{ Name: 'name', Values: [filter] },
{ Name: 'name', Values: [imageName] },
{ Name: 'state', Values: ['available'] },
];
return redisCached('awsEC2', `findAmiID-${region}-${filter}-${owners}`, 10 * 60, 0.5, () => {

return redisCached('awsEC2', `findAmiID-${region}-${imageName}-${actualOwners}`, 10 * 60, 0.5, () => {
return expBackOff(() => {
return metrics.trackRequestRegion(
region,
metrics.ec2DescribeImagesSuccess,
metrics.ec2DescribeImagesFailure,
() => {
return ec2
.describeImages({ Owners: [owners], Filters: filters })
.describeImages({ Owners: [actualOwners], Filters: filters })
.promise()
.then((data: EC2.DescribeImagesResult) => {
/* istanbul ignore next */
Expand Down
Loading