-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from mbonig/feat/wakeywakey
Feat/wakeywakey
- Loading branch information
Showing
16 changed files
with
419 additions
and
18 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,29 @@ | ||
const AWS = require('aws-sdk'); // eslint-disable-line | ||
const ec2 = new AWS.EC2(); | ||
|
||
const instanceId = process.env.INSTANCE_ID; | ||
export const handler = async (event: any) => { | ||
console.log({ event }); | ||
console.log({ instanceId }); | ||
|
||
console.log('Getting instance details'); | ||
|
||
let params = { | ||
InstanceIds: [ | ||
instanceId, | ||
], | ||
}; | ||
const { | ||
Reservations: [{ Instances: [instanceDetails] }], | ||
} = await ec2.describeInstances(params).promise(); | ||
console.log({ instanceDetails }); | ||
if (!instanceDetails) { | ||
throw new Error('Couldn\'t find instance details. Weird... if the instance was terminated, this app should be removed.'); | ||
} | ||
if (instanceDetails.State.Name === 'stopped') { | ||
console.log('starting the instance'); | ||
await ec2.startInstances(params).promise(); | ||
let now = new Date().toISOString(); | ||
console.log(`Started instance ${instanceId} at ${now}`); | ||
} | ||
}; |
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,27 @@ | ||
const AWS = require('aws-sdk'); // eslint-disable-line | ||
const rds = new AWS.RDS(); | ||
|
||
const dbInstanceIdentifier = process.env.DB_INSTANCE_IDENTIFIER; | ||
export const handler = async (event: any) => { | ||
console.log({ event }); | ||
console.log({ dbInstanceIdentifier }); | ||
console.log('Getting instance details'); | ||
let params = { | ||
DBInstanceIdentifier: dbInstanceIdentifier, | ||
}; | ||
const { | ||
DBInstances: [instanceDetails], | ||
} = await rds.describeDBInstances(params).promise(); | ||
console.log({ instanceDetails }); | ||
if (!instanceDetails) { | ||
throw new Error("Couldn't find instance details. Weird... if the instance was terminated, this app should be too"); | ||
} | ||
if (instanceDetails.DBInstanceStatus === 'stopped') { | ||
console.log('starting the instance'); | ||
await rds.startDBInstance({ DBInstanceIdentifier: dbInstanceIdentifier }).promise(); | ||
let now = new Date().toISOString(); | ||
console.log(`Started instance ${dbInstanceIdentifier} at ${now}`); | ||
} else { | ||
console.warn(`Not starting instance because the status is: ${instanceDetails.DBInstanceStatus}`); | ||
} | ||
}; |
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
Oops, something went wrong.