Skip to content

Commit

Permalink
Merge pull request #34 from GlueOps/fix/get-subnets
Browse files Browse the repository at this point in the history
fix: get subnets from aws
  • Loading branch information
NichArchA82 authored Oct 5, 2024
2 parents 7d42cf3 + a646daa commit f4dc0b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions command-handler/src/util/aws/aws-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import formatUser from '../format-user.js';
import getDevices from '../get-devices-info.js';
import getInstance from "./get-instances.js";
import getSecurityGroups from "./get-security-groups.js";
import getSubnets from "./get-subnets.js";
import configUserData from "../get-user-data.js";
import getAwsImages from "./get-aws-images.js";
import axiosError from '../axios-error-handler.js';
Expand Down Expand Up @@ -72,6 +73,7 @@ export default {
"MaxCount": 1,
"MinCount": 1,
"SecurityGroupIds": await getSecurityGroups({ region }),
"SubnetId": await getSubnets({ region }),
"TagSpecifications": [
{
"ResourceType": "instance",
Expand Down
16 changes: 16 additions & 0 deletions command-handler/src/util/aws/get-subnets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DescribeSubnetsCommand, EC2Client } from "@aws-sdk/client-ec2";

export default async function getSubnets({ region }) {
const client = new EC2Client({ region });
try {
const { Subnets } = await client.send(new DescribeSubnetsCommand({}));

const filteredSubnets = Subnets.filter(s =>
s.Tags && s.Tags.some(tag => tag.Key === 'purpose' && tag.Value === 'cloud-developer-environments')
);

return filteredSubnets.map(s => s.SubnetId)[0];
} catch (error) {
console.error("Error retrieving subnets:", error);
}
}

0 comments on commit f4dc0b8

Please sign in to comment.