-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add listing for latest ubuntu 20.04 image
- Loading branch information
1 parent
fdac515
commit ee77fe1
Showing
3 changed files
with
1,126 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
EC2Client, | ||
DescribeImagesCommand, | ||
DescribeImagesCommandInput, | ||
DescribeImagesCommandOutput, | ||
Filter, | ||
EC2ClientConfig, | ||
} from "@aws-sdk/client-ec2"; | ||
import { Config } from "aws-sdk"; | ||
import { response } from "express"; | ||
// Set the AWS Region. | ||
// TODO : Get info from params | ||
|
||
async function get_all_images( | ||
img_names: Array<string>, | ||
config: EC2ClientConfig | ||
): Promise<DescribeImagesCommandOutput["Images"]> { | ||
// Create anAmazon EC2 service client object. | ||
const ec2Client = new EC2Client(config); | ||
const input: DescribeImagesCommandInput = { | ||
Filters: [ | ||
{ Name: "architecture", Values: ["x86_64"] }, | ||
{ Name: "is-public", Values: ["true"] }, | ||
{ Name: "image-type", Values: ["machine"] }, | ||
{ Name: "state", Values: ["available"] }, | ||
{ | ||
Name: "name", | ||
Values: img_names, | ||
}, | ||
], | ||
Owners: ["099720109477"], | ||
IncludeDeprecated: false, | ||
}; | ||
const command = new DescribeImagesCommand(input); | ||
const response = await ec2Client.send(command); | ||
return response.Images.sort( | ||
(a, b) => | ||
new Date(a.CreationDate).getTime() - new Date(b.CreationDate).getTime() | ||
); | ||
} | ||
|
||
async function get_latest_image( | ||
config: EC2ClientConfig, | ||
img_names: Array<string> = [ | ||
"ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-????????", | ||
] | ||
) { | ||
let resp = (await get_all_images(img_names, config)).pop(); | ||
console.log(resp); | ||
return resp; | ||
} |
Oops, something went wrong.