Skip to content
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

Use named handler export rather than default export for lambdas #37

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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;