Add aws key management
This commit is contained in:
parent
37b6a03204
commit
92c8ecb5d7
20
index.mjs
20
index.mjs
@ -1,9 +1,23 @@
|
|||||||
import { Client } from 'ssh2';
|
import { Client } from 'ssh2';
|
||||||
|
import {
|
||||||
|
SecretsManagerClient,
|
||||||
|
GetSecretValueCommand,
|
||||||
|
} from "@aws-sdk/client-secrets-manager";
|
||||||
export const handler = async (event) => {
|
export const handler = async (event) => {
|
||||||
let result = "did not send";
|
let result = "did not send";
|
||||||
if (event.subject == "You have deliveries" || event.subject == "You have a delivery"){
|
if (event.subject == "You have deliveries" || event.subject == "You have a delivery") {
|
||||||
// Trigger home notification
|
// Trigger home notification
|
||||||
console.info("Matched Subject");
|
console.info("Matched Subject, pull key");
|
||||||
|
const keyClient = new SecretsManagerClient({ region: "us-west-2" });
|
||||||
|
let keyResponse;
|
||||||
|
try {
|
||||||
|
keyResponse = await keyClient.send(new GetSecretValueCommand({
|
||||||
|
SecretId: process.env.TRIGGER_SECRET
|
||||||
|
}));
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(err);
|
||||||
|
result = err;
|
||||||
|
}
|
||||||
const command = `ssh ${process.env.INTERNAL_HOST} "/usr/bin/tmux neww -d \"/usr/bin/mplayer '${process.env.INTERNAL_FILE}'\""`;
|
const command = `ssh ${process.env.INTERNAL_HOST} "/usr/bin/tmux neww -d \"/usr/bin/mplayer '${process.env.INTERNAL_FILE}'\""`;
|
||||||
console.info("Import ssh2");
|
console.info("Import ssh2");
|
||||||
const connection = new Client();
|
const connection = new Client();
|
||||||
@ -27,7 +41,7 @@ export const handler = async (event) => {
|
|||||||
host: process.env.TRIGGER_HOST,
|
host: process.env.TRIGGER_HOST,
|
||||||
port: 22,
|
port: 22,
|
||||||
username: process.env.TRIGGER_USERNAME,
|
username: process.env.TRIGGER_USERNAME,
|
||||||
privateKey: process.env.TRIGGER_PRIVATEKEY
|
privateKey: keyResponse.SecretString
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const response = {
|
const response = {
|
||||||
|
1268
package-lock.json
generated
1268
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"deploy": "npm run lint && npm run package && aws lambda update-function-code --function-name Deliveries --region us-west-2 --zip-file fileb://./lambda.zip",
|
"deploy": "npm run lint && npm run package && aws lambda update-function-code --function-name Deliveries --region us-west-2 --zip-file fileb://./lambda.zip",
|
||||||
"package": "zip -r -9 lambda.zip .",
|
"package": "zip -r -9 lambda.zip .",
|
||||||
"lint": "npx eslint index.mjs --fix"
|
"lint": "npx eslint index.mjs --fix"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -15,6 +15,7 @@
|
|||||||
"author": "Elizabeth Cray",
|
"author": "Elizabeth Cray",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aws-sdk/client-secrets-manager": "^3.665.0",
|
||||||
"@stylistic/eslint-plugin": "^2.8.0",
|
"@stylistic/eslint-plugin": "^2.8.0",
|
||||||
"ssh2": "^1.16.0"
|
"ssh2": "^1.16.0"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user