Skip to content

Commit

Permalink
Merge branch 'main' into dashboard-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
tbolt committed Jan 16, 2025
2 parents 84669fe + 61b4573 commit c8c5abb
Show file tree
Hide file tree
Showing 439 changed files with 6,417 additions and 17,653 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ jobs:
role-duration-seconds: 10800
- name: Run e2e tests
run: run e2e
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
join_by() { local IFS="$1"; shift; echo "$*"; }
echo "["$(join_by "," "${resourceData[@]}")"]" > "resources/aws-resources.json"
- name: Archive stage resources
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: aws-resources-${{ startsWith(github.ref_name, 'snyk-') && 'snyk' || github.ref_name }}
path: resources/aws-resources.json
Expand Down
10 changes: 2 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"editor.formatOnSave": true,
"tailwindCSS.experimental.classRegex": [
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
],
"tailwindCSS.experimental.classRegex": [["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]],
"typescript.tsdk": "node_modules/typescript/lib",
"cSpell.words": [
"Cpoc",
"Cpocs",
"opensearch"
]
"cSpell.words": ["Cpoc", "Cpocs", "opensearch"]
}
9 changes: 2 additions & 7 deletions bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import * as cdk from "aws-cdk-lib";
import { ParentStack } from "../lib/stacks/parent";
import { DeploymentConfig } from "../lib/config/deployment-config";
import { getSecret, validateEnvVariable } from "shared-utils";
import {
IamPathAspect,
IamPermissionsBoundaryAspect,
} from "../lib/local-aspects";
import { IamPathAspect, IamPermissionsBoundaryAspect } from "../lib/local-aspects";

async function main() {
try {
Expand Down Expand Up @@ -36,9 +33,7 @@ async function main() {
});

cdk.Aspects.of(app).add(
new IamPermissionsBoundaryAspect(
deploymentConfig.config.iamPermissionsBoundary,
),
new IamPermissionsBoundaryAspect(deploymentConfig.config.iamPermissionsBoundary),
);
cdk.Aspects.of(app).add(new IamPathAspect(deploymentConfig.config.iamPath));
} catch (error) {
Expand Down
35 changes: 6 additions & 29 deletions bin/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import { Argv } from "yargs";
import {
checkIfAuthenticated,
runCommand,
project,
region,
writeUiEnvFile,
} from "../lib/";
import { checkIfAuthenticated, runCommand, project, region, writeUiEnvFile } from "../lib/";
import path from "path";
import { execSync } from "child_process";
import {
CloudFrontClient,
CreateInvalidationCommand,
} from "@aws-sdk/client-cloudfront";
import { CloudFrontClient, CreateInvalidationCommand } from "@aws-sdk/client-cloudfront";
import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm";

export const deploy = {
Expand All @@ -22,11 +13,7 @@ export const deploy = {
},
handler: async (options: { stage: string; stack?: string }) => {
await checkIfAuthenticated();
await runCommand(
"cdk",
["deploy", "-c", `stage=${options.stage}`, "--all"],
".",
);
await runCommand("cdk", ["deploy", "-c", `stage=${options.stage}`, "--all"], ".");

await writeUiEnvFile(options.stage);

Expand Down Expand Up @@ -57,16 +44,8 @@ export const deploy = {
// There's a mime type issue when aws s3 syncing files up
// Empirically, this issue never presents itself if the bucket is cleared just before.
// Until we have a neat way of ensuring correct mime types, we'll remove all files from the bucket.
await runCommand(
"aws",
["s3", "rm", `s3://${s3BucketName}/`, "--recursive"],
".",
);
await runCommand(
"aws",
["s3", "sync", buildDir, `s3://${s3BucketName}/`],
".",
);
await runCommand("aws", ["s3", "rm", `s3://${s3BucketName}/`, "--recursive"], ".");
await runCommand("aws", ["s3", "sync", buildDir, `s3://${s3BucketName}/`], ".");

const cloudfrontClient = new CloudFrontClient({
region,
Expand All @@ -82,9 +61,7 @@ export const deploy = {
},
};

await cloudfrontClient.send(
new CreateInvalidationCommand(invalidationParams),
);
await cloudfrontClient.send(new CreateInvalidationCommand(invalidationParams));

console.log(
`Deployed UI to S3 bucket ${s3BucketName} and invalidated CloudFront distribution ${cloudfrontDistributionId}`,
Expand Down
27 changes: 4 additions & 23 deletions bin/cli/src/commands/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,10 @@ import {
DeleteStackCommand,
waitUntilStackDeleteComplete,
} from "@aws-sdk/client-cloudformation";
import {
checkIfAuthenticated,
confirmDestroyCommand,
project,
region,
} from "../lib";
import { checkIfAuthenticated, confirmDestroyCommand, project, region } from "../lib";

const waitForStackDeleteComplete = async (
client: CloudFormationClient,
stackName: string,
) => {
return waitUntilStackDeleteComplete(
{ client, maxWaitTime: 3600 },
{ StackName: stackName },
);
const waitForStackDeleteComplete = async (client: CloudFormationClient, stackName: string) => {
return waitUntilStackDeleteComplete({ client, maxWaitTime: 3600 }, { StackName: stackName });
};

export const destroy = {
Expand All @@ -33,15 +22,7 @@ export const destroy = {
demandOption: false,
default: true,
}),
handler: async ({
stage,
wait,
verify,
}: {
stage: string;
wait: boolean;
verify: boolean;
}) => {
handler: async ({ stage, wait, verify }: { stage: string; wait: boolean; verify: boolean }) => {
await checkIfAuthenticated();

const stackName = `${project}-${stage}`;
Expand Down
22 changes: 5 additions & 17 deletions bin/cli/src/commands/get-cost.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Argv } from "yargs";
import {
CostExplorerClient,
GetCostAndUsageCommand,
} from "@aws-sdk/client-cost-explorer";
import { CostExplorerClient, GetCostAndUsageCommand } from "@aws-sdk/client-cost-explorer";
import { checkIfAuthenticated, setStageFromBranch, project } from "../lib";

export const getCost = {
Expand Down Expand Up @@ -34,21 +31,14 @@ export const getCost = {

const dailyCosts = await getDailyStackCosts(tags, start, end);
const yesterdayCost = dailyCosts[dailyCosts.length - 1].cost;
const averageDailyCost =
dailyCosts.reduce((acc, day) => acc + day.cost, 0) / dailyCosts.length;
const averageDailyCost = dailyCosts.reduce((acc, day) => acc + day.cost, 0) / dailyCosts.length;

console.log(`Daily costs for the last 14 days:`);
dailyCosts.forEach((day) => {
console.log(`${day.date}: $${day.cost.toFixed(2)}`);
});
console.log(
`Average daily cost over the past 14 days: $${averageDailyCost.toFixed(
2,
)}`,
);
console.log(
`Yesterday, the stack ${stage} cost $${yesterdayCost.toFixed(2)}.`,
);
console.log(`Average daily cost over the past 14 days: $${averageDailyCost.toFixed(2)}`);
console.log(`Yesterday, the stack ${stage} cost $${yesterdayCost.toFixed(2)}.`);
},
};

Expand Down Expand Up @@ -90,9 +80,7 @@ export async function getDailyStackCosts(

return results.map((result) => ({
date: result.TimePeriod?.Start || "",
cost: result.Total?.BlendedCost?.Amount
? parseFloat(result.Total.BlendedCost.Amount)
: 0,
cost: result.Total?.BlendedCost?.Amount ? parseFloat(result.Total.BlendedCost.Amount) : 0,
}));
} catch (error) {
throw new Error(`Failed to fetch cost: ${error}`);
Expand Down
30 changes: 8 additions & 22 deletions bin/cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Argv } from "yargs";
import {
checkIfAuthenticated,
runCommand,
project,
region,
setStageFromBranch,
} from "../lib/";
import { checkIfAuthenticated, runCommand, project, region, setStageFromBranch } from "../lib/";
import {
ResourceGroupsTaggingAPIClient,
GetResourcesCommand,
Expand All @@ -24,13 +18,11 @@ export const logs = {
command: "logs",
describe: "Stream a lambda's cloudwatch logs.",
builder: (yargs: Argv) =>
yargs
.option("stage", { type: "string", demandOption: false })
.option("functionName", {
alias: "f",
type: "string",
demandOption: true,
}),
yargs.option("stage", { type: "string", demandOption: false }).option("functionName", {
alias: "f",
type: "string",
demandOption: true,
}),
handler: async (options: { stage?: string; functionName: string }) => {
await checkIfAuthenticated();
const stage = options.stage || (await setStageFromBranch());
Expand Down Expand Up @@ -77,11 +69,7 @@ export const logs = {
const lambdaLogGroup = await getLambdaLogGroup(lambda);

// Stream the logs
await runCommand(
"awslogs",
["get", lambdaLogGroup, "-s10m", "--watch"],
".",
);
await runCommand("awslogs", ["get", lambdaLogGroup, "-s10m", "--watch"], ".");
},
};

Expand Down Expand Up @@ -115,9 +103,7 @@ async function getLambdasWithTags(tags: Tag[]): Promise<string[]> {
}

// Extract Lambda function ARNs from the response
const lambdaArns = data.ResourceTagMappingList.map(
(resource) => resource.ResourceARN!,
);
const lambdaArns = data.ResourceTagMappingList.map((resource) => resource.ResourceARN!);

// Fetch Lambda function names from their ARNs
const lambdaNames = await Promise.all(
Expand Down
16 changes: 3 additions & 13 deletions bin/cli/src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import { Argv } from "yargs";
import {
checkIfAuthenticated,
openUrl,
project,
setStageFromBranch,
} from "../lib";
import { checkIfAuthenticated, openUrl, project, setStageFromBranch } from "../lib";
import { GetParameterCommand, SSMClient } from "@aws-sdk/client-ssm";

const createOpenCommand = (
name: string,
describe: string,
exportName: string,
) => ({
const createOpenCommand = (name: string, describe: string, exportName: string) => ({
command: name,
describe: describe,
builder: (yargs: Argv) =>
yargs.option("stage", { type: "string", demandOption: false }),
builder: (yargs: Argv) => yargs.option("stage", { type: "string", demandOption: false }),
handler: async (options: { stage?: string }) => {
await checkIfAuthenticated();
const stage = options.stage || (await setStageFromBranch());
Expand Down
4 changes: 1 addition & 3 deletions bin/cli/src/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ export const test = {
})
.check((argv) => {
if (argv.coverage && argv.ui) {
throw new Error(
"You cannot use both --watch and --ui at the same time.",
);
throw new Error("You cannot use both --watch and --ui at the same time.");
}
return true;
});
Expand Down
7 changes: 1 addition & 6 deletions bin/cli/src/commands/ui.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Argv } from "yargs";
import {
checkIfAuthenticated,
runCommand,
setStageFromBranch,
writeUiEnvFile,
} from "../lib";
import { checkIfAuthenticated, runCommand, setStageFromBranch, writeUiEnvFile } from "../lib";

export const ui = {
command: "ui",
Expand Down
13 changes: 2 additions & 11 deletions bin/cli/src/commands/watch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { Argv } from "yargs";
import {
checkIfAuthenticated,
runCommand,
setStageFromBranch,
writeUiEnvFile,
} from "../lib/";
import { checkIfAuthenticated, runCommand, setStageFromBranch, writeUiEnvFile } from "../lib/";

export const watch = {
command: "watch",
Expand All @@ -18,10 +13,6 @@ export const watch = {

await writeUiEnvFile(stage);

await runCommand(
"cdk",
["watch", "-c", `stage=${stage}`, "--no-rollback"],
".",
);
await runCommand("cdk", ["watch", "-c", `stage=${stage}`, "--no-rollback"], ".");
},
};
4 changes: 1 addition & 3 deletions bin/cli/src/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export function validateEnvVariable(variableName: string): string {
const value = process.env[variableName];
if (!value) {
throw new Error(
`Environment variable ${variableName} is required but not set`,
);
throw new Error(`Environment variable ${variableName} is required but not set`);
}
return value;
}
9 changes: 2 additions & 7 deletions bin/cli/src/lib/sts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ export async function checkIfAuthenticated(): Promise<void> {
await client.send(command);
} catch (error) {
if (error instanceof Error) {
if (
error.message.includes("Could not load credentials from any providers")
) {
if (error.message.includes("Could not load credentials from any providers")) {
console.error(
`\x1b[31m\x1b[1mERROR: This command requires AWS credentials available to your terminal. Please configure AWS credentials and try again.\x1b[0m`,
);
} else {
console.error(
"Error occurred while checking authentication:",
error.message,
);
console.error("Error occurred while checking authentication:", error.message);
}
} else {
console.error("An unknown error occurred:", error);
Expand Down
4 changes: 1 addition & 3 deletions bin/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"incremental": true /* Enable incremental compilation */,
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": [
"ES2021"
] /* Specify library files to be included in the compilation. */,
"lib": ["ES2021"] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
Loading

0 comments on commit c8c5abb

Please sign in to comment.