Skip to content
Merged
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
3 changes: 2 additions & 1 deletion javascriptv3/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/example_code/reactnative/
/example_code/medical-imaging/scenarios/health-image-sets/pixel-data-verification
/example_code/kinesis/kinesis-cdk
/example_code/kinesis/kinesis-cdk
**/dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import { describe, it, vi, expect } from "vitest";
import { CloudWatchQuery } from "../scenarios/large-query/cloud-watch-query.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import {
DeleteAlarmsCommand,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import { describe, it, expect } from "vitest";
import { v4 as uuidv4 } from "uuid";
import { getMetricData } from "../libs/cloudwatch-helper.js";
Expand Down
211 changes: 108 additions & 103 deletions javascriptv3/example_code/codepipeline/MyCodePipelineFunction.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,108 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0


// snippet-start:[codepipeline.javascript.MyCodePipelineFunction.complete]

var assert = require('assert');
var AWS = require('aws-sdk');
var http = require('http');

exports.handler = function(event, context) {

var codepipeline = new AWS.CodePipeline();

// Retrieve the Job ID from the Lambda action
var jobId = event["CodePipeline.job"].id;

// Retrieve the value of UserParameters from the Lambda action configuration in AWS CodePipeline, in this case a URL which will be
// health checked by this function.
var url = event["CodePipeline.job"].data.actionConfiguration.configuration.UserParameters;

// Notify AWS CodePipeline of a successful job
var putJobSuccess = function(message) {
var params = {
jobId: jobId
};
codepipeline.putJobSuccessResult(params, function(err, data) {
if(err) {
context.fail(err);
} else {
context.succeed(message);
}
});
};

// Notify AWS CodePipeline of a failed job
var putJobFailure = function(message) {
var params = {
jobId: jobId,
failureDetails: {
message: JSON.stringify(message),
type: 'JobFailed',
externalExecutionId: context.invokeid
}
};
codepipeline.putJobFailureResult(params, function(err, data) {
context.fail(message);
});
};

// Validate the URL passed in UserParameters
if(!url || url.indexOf('http://') === -1) {
putJobFailure('The UserParameters field must contain a valid URL address to test, including http:// or https://');
return;
}

// Helper function to make a HTTP GET request to the page.
// The helper will test the response and succeed or fail the job accordingly
var getPage = function(url, callback) {
var pageObject = {
body: '',
statusCode: 0,
contains: function(search) {
return this.body.indexOf(search) > -1;
}
};
http.get(url, function(response) {
pageObject.body = '';
pageObject.statusCode = response.statusCode;

response.on('data', function (chunk) {
pageObject.body += chunk;
});

response.on('end', function () {
callback(pageObject);
});

response.resume();
}).on('error', function(error) {
// Fail the job if our request failed
putJobFailure(error);
});
};

getPage(url, function(returnedPage) {
try {
// Check if the HTTP response has a 200 status
assert(returnedPage.statusCode === 200);
// Check if the page contains the text "Congratulations"
// You can change this to check for different text, or add other tests as required
assert(returnedPage.contains('Congratulations'));

// Succeed the job
putJobSuccess("Tests passed.");
} catch (ex) {
// If any of the assertions failed then fail the job
putJobFailure(ex);
}
});
};

// snippet-end:[codepipeline.javascript.MyCodePipelineFunction.complete]
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

// snippet-start:[codepipeline.javascript.MyCodePipelineFunction.complete]

var assert = require("assert");
var AWS = require("aws-sdk");
var http = require("http");

exports.handler = function (event, context) {
var codepipeline = new AWS.CodePipeline();

// Retrieve the Job ID from the Lambda action
var jobId = event["CodePipeline.job"].id;

// Retrieve the value of UserParameters from the Lambda action configuration in AWS CodePipeline, in this case a URL which will be
// health checked by this function.
var url =
event["CodePipeline.job"].data.actionConfiguration.configuration
.UserParameters;

// Notify AWS CodePipeline of a successful job
var putJobSuccess = function (message) {
var params = {
jobId: jobId,
};
codepipeline.putJobSuccessResult(params, function (err, data) {
if (err) {
context.fail(err);
} else {
context.succeed(message);
}
});
};

// Notify AWS CodePipeline of a failed job
var putJobFailure = function (message) {
var params = {
jobId: jobId,
failureDetails: {
message: JSON.stringify(message),
type: "JobFailed",
externalExecutionId: context.invokeid,
},
};
codepipeline.putJobFailureResult(params, function (err, data) {
context.fail(message);
});
};

// Validate the URL passed in UserParameters
if (!url || url.indexOf("http://") === -1) {
putJobFailure(
"The UserParameters field must contain a valid URL address to test, including http:// or https://",
);
return;
}

// Helper function to make a HTTP GET request to the page.
// The helper will test the response and succeed or fail the job accordingly
var getPage = function (url, callback) {
var pageObject = {
body: "",
statusCode: 0,
contains: function (search) {
return this.body.indexOf(search) > -1;
},
};
http
.get(url, function (response) {
pageObject.body = "";
pageObject.statusCode = response.statusCode;

response.on("data", function (chunk) {
pageObject.body += chunk;
});

response.on("end", function () {
callback(pageObject);
});

response.resume();
})
.on("error", function (error) {
// Fail the job if our request failed
putJobFailure(error);
});
};

getPage(url, function (returnedPage) {
try {
// Check if the HTTP response has a 200 status
assert(returnedPage.statusCode === 200);
// Check if the page contains the text "Congratulations"
// You can change this to check for different text, or add other tests as required
assert(returnedPage.contains("Congratulations"));

// Succeed the job
putJobSuccess("Tests passed.");
} catch (ex) {
// If any of the assertions failed then fail the job
putJobFailure(ex);
}
});
};

// snippet-end:[codepipeline.javascript.MyCodePipelineFunction.complete]
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import { Handler } from "src/types/handler.js";
import { command as getAllItemsCommand } from "../statement-commands/get-all-items.js";
import { command as getArchivedItemsCommand } from "../statement-commands/get-archived-items.js";
Expand All @@ -18,7 +20,7 @@ const getItemsHandler: Handler = {
};

const response = await rdsDataClient.send<{ records: DBRecords }>(
commands[archived] || getAllItemsCommand
commands[archived] || getAllItemsCommand,
);

res.send(response.records.map(parseItem));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import { v4 as uuidv4 } from "uuid";
import { Handler } from "src/types/handler.js";
import { Item } from "src/types/item.js";
Expand All @@ -12,7 +14,7 @@ const postItemsHandler: Handler = {
const { description, guide, status, name }: Item = req.body;
const command = buildStatementCommand(
"insert into items (iditem, description, guide, status, username, archived)\n" +
`values ("${uuidv4()}", "${description}", "${guide}", "${status}", "${name}", 0)`
`values ("${uuidv4()}", "${description}", "${guide}", "${status}", "${name}", 0)`,
);

await rdsDataClient.send(command);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import { SendRawEmailCommand } from "@aws-sdk/client-ses";
import { createMimeMessage, TextFormat } from "mimetext";
import { format } from "prettier";
Expand Down Expand Up @@ -47,7 +49,7 @@ const csvToHtmlTable = (csv: string) => {

const buildSendRawEmailCommand = (
emailAddress: string,
reportData: { csv: string; date: string; itemCount: number }
reportData: { csv: string; date: string; itemCount: number },
) => {
const msg = createMimeMessage();
msg.setSender({ name: emailAddress.split("@")[0], addr: emailAddress });
Expand All @@ -56,13 +58,13 @@ const buildSendRawEmailCommand = (
msg.setMessage(
"text/html",
`<h1>Item Report</h1>
${csvToHtmlTable(reportData.csv)}`
${csvToHtmlTable(reportData.csv)}`,
);
msg.setMessage("text/plain", "Report");
msg.setAttachment(
"report.csv",
"text/csv" as TextFormat,
Buffer.from(reportData.csv).toString("base64")
Buffer.from(reportData.csv).toString("base64"),
);

return new SendRawEmailCommand({
Expand All @@ -77,7 +79,7 @@ const postItemsReportHandler: Handler = {
({ rdsDataClient, sesClient }) =>
async (req, res) => {
const { records } = await rdsDataClient.send<{ records: DBRecords }>(
getActiveItemsCommand
getActiveItemsCommand,
);
const date = new Date().toLocaleString("en-US");
const csv = makeCsv(records);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import type { Handler } from "src/types/handler.js";
import { buildStatementCommand } from "../statement-commands/command-helper.js";

Expand All @@ -10,7 +12,7 @@ const putItemsArchiveHandler: Handler = {
const { itemId } = req.params;

const command = buildStatementCommand(
"update items\n" + "set archived = 1\n" + `where iditem = "${itemId}"`
"update items\n" + "set archived = 1\n" + `where iditem = "${itemId}"`,
);

await rdsDataClient.send(command);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import express from "express";
import cors from "cors";
import { rdsDataClient, sesClient } from "./client.js";
Expand All @@ -22,14 +24,14 @@ exp.get("/api/items", getItemsHandler.withClient({ rdsDataClient }));

exp.post(
"/api/items\\:report",
postItemsReportHandler.withClient({ rdsDataClient, sesClient })
postItemsReportHandler.withClient({ rdsDataClient, sesClient }),
);

exp.post("/api/items", postItemsHandler.withClient({ rdsDataClient }));

exp.put(
"/api/items/:itemId\\:archive",
putItemsArchiveHandler.withClient({ rdsDataClient })
putItemsArchiveHandler.withClient({ rdsDataClient }),
);

exp.listen(port, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import { RequestHandler } from "express";
import { command as createTableCommand } from "../statement-commands/create-table.js";
import { command as getAllItemsCommand } from "../statement-commands/get-all-items.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

declare interface Sendable {
send: <R = any>(command: any) => Promise<R>
}
send: <R = any>(command: any) => Promise<R>;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/* eslint-disable -- This file existed pre-eslint configuration. Fix the next time the file is touched. */

import { spawn } from "node:child_process";

const format = (data) => data.toString().trim();
Expand All @@ -15,7 +17,9 @@ const loadApp = (app) => {
app.kill();
}

const newApp = spawn("node", ["./build/cross-services/aurora-serverless-app/src/index.js"]);
const newApp = spawn("node", [
"./build/cross-services/aurora-serverless-app/src/index.js",
]);
newApp.stdout.on("data", (data) => appLogger(format(data)));
newApp.stderr.on("data", (data) => appLogger(format(data)));
return newApp;
Expand Down
Loading
Loading