Skip to content

Commit

Permalink
Merge pull request #37 from ajmacd/ajm-named-handler-export
Browse files Browse the repository at this point in the history
Use named handler export rather than default export for lambdas
  • Loading branch information
rileydakota authored Jan 11, 2025
2 parents b90374d + c2ecf62 commit 2d73b1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 4 additions & 6 deletions resources/serverstatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ec2Client = new EC2Client({ region: REGION });
/**
* Everything here has the assumption there is only one task.
*/
const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context: Context) => {
export const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context: Context) => {
console.log(`New getServerStatus request: ${JSON.stringify(event)}`);
console.log(`With context: ${JSON.stringify(context)}`);

Expand All @@ -50,8 +50,6 @@ const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context:
};
};

export default handler;

async function getIPFunction() {

// Define the object that will hold the data values returned
Expand All @@ -62,15 +60,15 @@ async function getIPFunction() {

try {

const listTasksCommandInput: ListTasksCommandInput = {
const listTasksCommandInput: ListTasksCommandInput = {
serviceName: SERVICE_ARN,
cluster: CLUSTER_ARN,
desiredStatus: "RUNNING"
}
const listTasksCommandResult = await ecsClient.send(new ListTasksCommand(listTasksCommandInput));
console.log(listTasksCommandResult);

if (!listTasksCommandResult.taskArns || listTasksCommandResult.taskArns.length <= 0) return;
if (!listTasksCommandResult.taskArns || listTasksCommandResult.taskArns.length <= 0) return statusResults;

const networkInterfaceId = await getNetworkInterfaceId(CLUSTER_ARN, listTasksCommandResult.taskArns);

Expand All @@ -79,7 +77,7 @@ async function getIPFunction() {
}
const describeNetworkInterfacesResult = await ec2Client.send(new DescribeNetworkInterfacesCommand(describeNetworkInterfacesInput));

if (!describeNetworkInterfacesResult.NetworkInterfaces || describeNetworkInterfacesResult.NetworkInterfaces.length <= 0) return;
if (!describeNetworkInterfacesResult.NetworkInterfaces || describeNetworkInterfacesResult.NetworkInterfaces.length <= 0) return statusResults;
const publicIp = describeNetworkInterfacesResult.NetworkInterfaces.find(x => x.Association != undefined)?.Association?.PublicIp;

console.log("found public IP " + publicIp);
Expand Down
10 changes: 3 additions & 7 deletions resources/startstopserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const SERVICE_NAME = process.env.SERVICE_NAME;
const CLUSTER_ARN = process.env.CLUSTER_ARN;
const PASSWORD = process.env.PASSWORD;

const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context: Context) => {
export const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context: Context) => {
console.log("request: " + JSON.stringify(event));
let responseCode = 400;
let message = "authentication failed";
Expand Down Expand Up @@ -54,10 +54,8 @@ const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context:

const updateCommand = new UpdateServiceCommand(params);

client.send(updateCommand).then(
(data) => {console.log(data);},
(err) => { console.log(err);}
);
const updateCommandResult = await client.send(updateCommand);
console.log(updateCommandResult);
}
}

Expand All @@ -78,5 +76,3 @@ const handler: APIGatewayProxyHandler = async (event: APIGatewayEvent, context:
body: JSON.stringify(responseBody)
};
};

export default handler;

0 comments on commit 2d73b1a

Please sign in to comment.