Skip to content

Commit

Permalink
CMDCT-4184 - fixing build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
peoplespete committed Feb 3, 2025
1 parent 7a7b2be commit 76bb00e
Show file tree
Hide file tree
Showing 16 changed files with 492 additions and 5,349 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
SKIP_PREFLIGHT_CHECK: true
- id: endpoint
run: |
APPLICATION_ENDPOINT=$(./output.sh ui ApplicationEndpointUrl $STAGE_PREFIX$branch_name)
APPLICATION_ENDPOINT=$(./output.sh seds-$STAGE_PREFIX$branch_name CloudFrontUrl)
echo "application_endpoint=$APPLICATION_ENDPOINT" >> $GITHUB_OUTPUT
echo "## Application Endpoint" >> $GITHUB_STEP_SUMMARY
echo "<$APPLICATION_ENDPOINT>" >> $GITHUB_STEP_SUMMARY
Expand Down
12 changes: 6 additions & 6 deletions deployment/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
import "source-map-support/register";
import * as cdk from "aws-cdk-lib";
import { WithoutImportsParentStack } from "./stacks/without_imports/parent";
import { WithImportsParentStack} from "./stacks/with_imports/parent";
import { EmptyParentStack } from "./stacks/empty/parent";
import { ImportsIncludedParentStack} from "./stacks/imports_included/parent";
import { ParentStack } from "./stacks/parent";
import { determineDeploymentConfig } from "./deployment-config";
import { getSecret } from "./utils/secrets-manager";
Expand Down Expand Up @@ -42,10 +42,10 @@ async function main() {
cdk.Tags.of(app).add("PROJECT", config.project);

let correctParentStack;
if (process.env.WITHOUT_IMPORTS) {
correctParentStack = WithoutImportsParentStack
} else if (process.env.WITH_IMPORTS) {
correctParentStack = WithImportsParentStack
if (process.env.IMPORT_VARIANT == "empty") {
correctParentStack = EmptyParentStack
} else if (process.env.IMPORT_VARIANT == "imports_included") {
correctParentStack = ImportsIncludedParentStack
} else {
correctParentStack = ParentStack
}
Expand Down
6 changes: 3 additions & 3 deletions deployment/import_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ cognito.UserPool -
1. Create just the new cdk stack without anything inside of it.

```bash
WITHOUT_IMPORTS=true ./run deploy --stage <YOUR_BRANCH_NAME>
IMPORT_VARIANT=empty ./run deploy --stage <YOUR_BRANCH_NAME>
```

2. Now import all the serverless ejected resources.

```bash
WITH_IMPORTS=true PROJECT=seds cdk import --context stage=<YOUR_BRANCH_NAME> --force
IMPORT_VARIANT=imports_included PROJECT=seds cdk import --context stage=<YOUR_BRANCH_NAME> --force
```
As this import occurs you'll have to provide the information you gathered just before destroying the serverless stacks. For the dynamo tables the default should be correct but read closely to be sure.

3. Run a deploy on that same imported resource set.

```bash
WITH_IMPORTS=true ./run deploy --stage <YOUR_BRANCH_NAME>
IMPORT_VARIANT=imports_included ./run deploy --stage <YOUR_BRANCH_NAME>
```

4. Run a full deploy by kicking off the full cdk deploy.
Expand Down
8 changes: 0 additions & 8 deletions deployment/stacks/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,6 @@ export function createApiComponents(props: CreateApiComponentsProps) {
tables: dataConnectTables,
});

new Lambda(scope, "exportToExcel", {
entry: "services/app-api/export/exportToExcel.js",
handler: "main",
path: "/export/export-to-excel",
method: "POST",
...commonProps,
});

new Lambda(scope, "getUserById", {
entry: "services/app-api/handlers/users/get/getUserById.js",
handler: "main",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "aws-cdk-lib";
import { DeploymentConfigProperties } from "../../deployment-config";

export class WithoutImportsParentStack extends Stack {
export class EmptyParentStack extends Stack {
constructor(
scope: Construct,
id: string,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createDataComponents } from "./data";
import { createUiComponents } from "./ui";
import { createUiAuthComponents } from "./ui-auth";

export class WithImportsParentStack extends Stack {
export class ImportsIncludedParentStack extends Stack {
constructor(
scope: Construct,
id: string,
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
"test": "tests"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"cdk": "cdk",
"build": "tsc",
"watch": "tsc -w",
"cdk": "cdk",
Expand Down Expand Up @@ -65,6 +62,7 @@
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
"constructs": "^10.3.0",
"jsonpath": "^1.1.0",
"readline-sync": "^1.4.10"
"readline-sync": "^1.4.10",
"source-map-support": "^0.5.21"
}
}
2 changes: 1 addition & 1 deletion run
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ fi

# build and run run.ts
# tsc is configured to build what we expect in tsconfig.json
./node_modules/.bin/tsc && node ./build_dev/run.js "${ARGS[@]-}"
./node_modules/.bin/tsc && node ./build_dev/src/run.js "${ARGS[@]-}"
8 changes: 4 additions & 4 deletions services/app-api/libs/authorization.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm";
import jwt_decode from "jwt-decode";
import { jwtDecode } from "jwt-decode";
import { CognitoJwtVerifier } from "aws-jwt-verify";
import * as logger from "./debug-lib.js";
import { SimpleJwksCache } from "aws-jwt-verify/jwk";
Expand All @@ -9,10 +9,10 @@ export async function getUserDetailsFromEvent(event) {
await verifyEventSignature(event);
const apiKey = event?.headers?.["x-api-key"];

// TODO, it seems that jwt_decode and verifier.verify may return the same object?
// Maybe we can remove the jwt_decode dependency.
// TODO, it seems that jwtDecode and verifier.verify may return the same object?
// Maybe we can remove the jwtDecode dependency.

const token = jwt_decode(apiKey);
const token = jwtDecode(apiKey);
const role = mapMembershipToRole(token["custom:ismemberof"]);

return {
Expand Down
22 changes: 4 additions & 18 deletions services/output.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@

set -e

help='This script is run with the format ./output.sh <target service name> <serverless output variable name> <stage name (optional, default dev)>'
example='ex. ./output.sh ui CloudFrontEndpointUrl'
help='This script is run with the format ./output.sh <target stack name> <cloudformation output variable name>'
example='ex. ./output.sh seds-cmdct-4184-cdk CloudFrontUrl'

: ${1?ERROR: 'You must specify the target service.'
$help
$example}
: ${2?ERROR: "You must specify the variable you want to fetch from serverless' output"
$help
$example}

service=${1}
stack_name=${1}
output=${2}
stage=${3}

if [ $output == "url" ]; then
output="CloudFrontEndpointUrl"
fi

cd $service
serverless info --stage $stage --json | jq --raw-output --arg output $output '.outputs[] | select(.OutputKey == $output) | .OutputValue'
cd ..
aws cloudformation describe-stacks --stack-name $stack_name --query "Stacks[0].Outputs[?OutputKey=='$output'].OutputValue" --output text
12 changes: 12 additions & 0 deletions services/ui-auth/handlers/createUsers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import {
SSMClient,
GetParameterCommand,
} from "@aws-sdk/client-ssm";
import * as cognitolib from "../libs/cognito-lib.js";
const userPoolId = process.env.userPoolId;
import users from "../libs/users.json" assert { type: "json" };

export async function handler(_event, _context, _callback) {
const command = new GetParameterCommand({
Name: process.env.bootstrapUsersPasswordArn,
WithDecryption: true,
});
const ssmClient = new SSMClient({});
const result = await ssmClient.send(command);
const password = result.Parameter?.Value;

for (let user of users) {
var poolData = {
UserPoolId: userPoolId,
Expand Down
2 changes: 1 addition & 1 deletion src/write-ui-env-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function writeUiEnvFile(stage: string, local = false) {
LOCAL_LOGIN: "false",
SKIP_PREFLIGHT_CHECK: "true",
API_REGION: region,
API_URL: deploymentOutput.apiGatewayRestApiUrl.slice(0, -1),
API_URL: deploymentOutput.apiGatewayRestApiUrl,
COGNITO_REGION: region,
COGNITO_IDENTITY_POOL_ID: deploymentOutput.identityPoolId,
COGNITO_USER_POOL_ID: deploymentOutput.userPoolId,
Expand Down
Loading

0 comments on commit 76bb00e

Please sign in to comment.