Skip to content

Commit 87b2887

Browse files
CMR-10282: Fix tests and prettier
1 parent 65a95df commit 87b2887

21 files changed

+395
-354
lines changed

.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
strategy:
1111
matrix:
12-
node_version: [18]
12+
node_version: [22]
1313

1414
steps:
1515
- uses: actions/checkout@v4
@@ -28,7 +28,7 @@ jobs:
2828
runs-on: ubuntu-latest
2929
strategy:
3030
matrix:
31-
node_version: [18]
31+
node_version: [22]
3232

3333
steps:
3434
- uses: actions/checkout@v4

.github/workflows/run_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
fail-fast: true
1717
matrix:
18-
node_version: [18]
18+
node_version: [22]
1919

2020
steps:
2121
- uses: actions/checkout@v4

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ node_modules
1111
pnpm-lock.yaml
1212
package-lock.json
1313
yarn.lock
14+
15+
cdk.out

cdk/cmr-stac-dev/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ The `cdk.json` file tells the CDK Toolkit how to execute your app.
66

77
## Useful commands
88

9-
* `npm run build` compile typescript to js
10-
* `npm run watch` watch for changes and compile
11-
* `npm run test` perform the jest unit tests
12-
* `npx cdk deploy` deploy this stack to your default AWS account/region
13-
* `npx cdk diff` compare deployed stack with current state
14-
* `npx cdk synth` emits the synthesized CloudFormation template
9+
- `npm run build` compile typescript to js
10+
- `npm run watch` watch for changes and compile
11+
- `npm run test` perform the jest unit tests
12+
- `npx cdk deploy` deploy this stack to your default AWS account/region
13+
- `npx cdk diff` compare deployed stack with current state
14+
- `npx cdk synth` emits the synthesized CloudFormation template

cdk/cmr-stac-dev/bin/cmr-stac-dev.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
#!/usr/bin/env node
2-
import * as cdk from 'aws-cdk-lib';
3-
import { CmrStacDevStack } from '../lib/cmr-stac-dev-stack';
2+
import * as cdk from "aws-cdk-lib";
3+
import { CmrStacDevStack } from "../lib/cmr-stac-dev-stack";
44

5-
const {
6-
AWS_ACCOUNT = '1234567890',
7-
AWS_REGION = 'us-east-1',
8-
STAGE_NAME = 'dev',
9-
} = process.env;
5+
const { AWS_ACCOUNT = "1234567890", AWS_REGION = "us-east-1", STAGE_NAME = "dev" } = process.env;
106
const app = new cdk.App();
117
new CmrStacDevStack(app, `cmr-stac-${STAGE_NAME}`, {
128
/* If you don't specify 'env', this stack will be environment-agnostic.

cdk/cmr-stac-dev/cdk.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"app": "npx ts-node --prefer-ts-exts bin/cmr-stac-dev.ts",
33
"watch": {
4-
"include": [
5-
"**"
6-
],
4+
"include": ["**"],
75
"exclude": [
86
"README.md",
97
"cdk*.json",
@@ -18,10 +16,7 @@
1816
"context": {
1917
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
2018
"@aws-cdk/core:checkSecretUsage": true,
21-
"@aws-cdk/core:target-partitions": [
22-
"aws",
23-
"aws-cn"
24-
],
19+
"@aws-cdk/core:target-partitions": ["aws", "aws-cn"],
2520
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
2621
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
2722
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,

cdk/cmr-stac-dev/jest.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export const testEnvironment = 'node';
2-
export const roots = ['<rootDir>/test'];
3-
export const testMatch = ['**/*.test.ts'];
1+
export const testEnvironment = "node";
2+
export const roots = ["<rootDir>/test"];
3+
export const testMatch = ["**/*.test.ts"];
44
export const transform = {
5-
'^.+\\.tsx?$': 'ts-jest'
5+
"^.+\\.tsx?$": "ts-jest",
66
};

cdk/cmr-stac-dev/lib/cmr-stac-dev-stack.ts

Lines changed: 62 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
1-
import * as cdk from 'aws-cdk-lib';
2-
import * as iam from 'aws-cdk-lib/aws-iam';
3-
import * as lambda from 'aws-cdk-lib/aws-lambda';
4-
import * as ec2 from 'aws-cdk-lib/aws-ec2';
1+
import * as cdk from "aws-cdk-lib";
2+
import * as iam from "aws-cdk-lib/aws-iam";
3+
import * as lambda from "aws-cdk-lib/aws-lambda";
4+
import * as ec2 from "aws-cdk-lib/aws-ec2";
55

6-
import { application } from '@edsc/cdk-utils';
6+
import { application } from "@edsc/cdk-utils";
77

8-
export type CmrStacStackProps = cdk.StackProps
8+
export type CmrStacStackProps = cdk.StackProps;
99

10-
const logGroupSuffix = ''
11-
const LOG_DESTINATION_ARN = 'local-arn'
12-
const STAGE_NAME = 'dev'
13-
const SUBNET_ID_A = 'local-subnet-a'
14-
const SUBNET_ID_B = 'local-subnet-b'
15-
const SUBNET_ID_C = 'local-subnet-c'
16-
const VPC_ID = 'local-vpc'
17-
const runtime = lambda.Runtime.NODEJS_22_X
18-
const memorySize = 1024
10+
const logGroupSuffix = "";
11+
const LOG_DESTINATION_ARN = "local-arn";
12+
const STAGE_NAME = "dev";
13+
const SUBNET_ID_A = "local-subnet-a";
14+
const SUBNET_ID_B = "local-subnet-b";
15+
const SUBNET_ID_C = "local-subnet-c";
16+
const VPC_ID = "local-vpc";
17+
const runtime = lambda.Runtime.NODEJS_22_X;
18+
const memorySize = 1024;
1919

2020
// Don't bundle lambda assets since this is the dev stack
2121
const bundling = {
2222
// Only minify in production
2323
minify: false,
24-
externalModules: ['@aws-sdk/*']
25-
}
24+
externalModules: ["@aws-sdk/*"],
25+
};
2626
/**
2727
* The AWS CloudFormation template for this Serverless application
2828
*/
2929
export class CmrStacDevStack extends cdk.Stack {
30-
3130
/**
3231
* URL of the service endpoint
33-
*/
32+
*/
3433
public readonly serviceEndpoint;
3534
/**
3635
* Current Lambda function version
@@ -40,58 +39,48 @@ export class CmrStacDevStack extends cdk.Stack {
4039
super(scope, id, props);
4140

4241
const environment = {
43-
CMR_URL: process.env.CMR_URL = '',
44-
CMR_LB_URL: process.env.CMR_LB_URL = '',
45-
GRAPHQL_URL: process.env.URS_ROOT_URL = '',
46-
NODE_ENV: 'development',
42+
CMR_URL: (process.env.CMR_URL = ""),
43+
CMR_LB_URL: (process.env.CMR_LB_URL = ""),
44+
GRAPHQL_URL: (process.env.URS_ROOT_URL = ""),
45+
NODE_ENV: "development",
4746
STAC_VERSION: "1.0.0",
4847
LOG_LEVEL: "1.0.0",
49-
PAGE_SIZE: "100"
50-
}
48+
PAGE_SIZE: "100",
49+
};
5150

52-
const cmrStacRole = new iam.CfnRole(this, 'cmrStacRole', {
51+
const cmrStacRole = new iam.CfnRole(this, "cmrStacRole", {
5352
roleName: `stacRole-${STAGE_NAME}`,
54-
permissionsBoundary: [
55-
'arn:aws:iam::',
56-
this.account,
57-
':policy/NGAPShRoleBoundary',
58-
].join(''),
59-
managedPolicyArns: [
60-
'arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole',
61-
],
53+
permissionsBoundary: ["arn:aws:iam::", this.account, ":policy/NGAPShRoleBoundary"].join(""),
54+
managedPolicyArns: ["arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"],
6255
assumeRolePolicyDocument: {
63-
Version: '2012-10-17',
56+
Version: "2012-10-17",
6457
Statement: [
6558
{
66-
Effect: 'Allow',
59+
Effect: "Allow",
6760
Principal: {
68-
Service: [
69-
'lambda.amazonaws.com',
70-
],
61+
Service: ["lambda.amazonaws.com"],
7162
},
72-
Action: [
73-
'sts:AssumeRole',
74-
],
63+
Action: ["sts:AssumeRole"],
7564
},
7665
],
7766
},
78-
})
67+
});
7968

8069
// Get lambda role from application role
81-
const lambdaRole = iam.Role.fromRoleArn(this, 'CmrStacLambdaRole', cmrStacRole.attrArn)
82-
83-
const vpc = ec2.Vpc.fromVpcAttributes(this, 'Vpc', {
84-
availabilityZones: ['us-east-1a', 'us-east-1b', 'us-east-1c'],
85-
privateSubnetIds: [
86-
SUBNET_ID_A,
87-
SUBNET_ID_B,
88-
SUBNET_ID_C,
89-
],
90-
vpcId: VPC_ID
70+
const lambdaRole = iam.Role.fromRoleArn(this, "CmrStacLambdaRole", cmrStacRole.attrArn);
71+
72+
const vpc = ec2.Vpc.fromVpcAttributes(this, "Vpc", {
73+
availabilityZones: ["us-east-1a", "us-east-1b", "us-east-1c"],
74+
privateSubnetIds: [SUBNET_ID_A, SUBNET_ID_B, SUBNET_ID_C],
75+
vpcId: VPC_ID,
9176
});
92-
93-
const lambdaSecurityGroup = ec2.SecurityGroup.fromSecurityGroupId(this, 'lambdaSecurityGroup', 'cmrStacLambdaSecurityGroup');
94-
77+
78+
const lambdaSecurityGroup = ec2.SecurityGroup.fromSecurityGroupId(
79+
this,
80+
"lambdaSecurityGroup",
81+
"cmrStacLambdaSecurityGroup"
82+
);
83+
9584
const defaultLambdaConfig = {
9685
bundling,
9786
environment,
@@ -102,44 +91,41 @@ export class CmrStacDevStack extends cdk.Stack {
10291
runtime,
10392
securityGroups: [lambdaSecurityGroup],
10493
stageName: STAGE_NAME,
105-
vpc
106-
}
94+
vpc,
95+
};
10796

108-
const apiGateway = new application.ApiGateway(this, 'ApiGateway', {
97+
const apiGateway = new application.ApiGateway(this, "ApiGateway", {
10998
apiName: `${STAGE_NAME}-cmr-stac`,
11099
stageName: STAGE_NAME,
111100
});
112101

113-
const {
114-
apiGatewayDeployment,
115-
apiGatewayRestApi
116-
} = apiGateway
117-
118-
new application.NodeJsFunction(this, 'StacLambdaFunction', {
102+
const { apiGatewayDeployment, apiGatewayRestApi } = apiGateway;
103+
104+
new application.NodeJsFunction(this, "StacLambdaFunction", {
119105
...defaultLambdaConfig,
120106
api: {
121107
apiGatewayDeployment,
122108
apiGatewayRestApi,
123-
methods: ['GET', 'POST'],
124-
path: '{proxy+}',
109+
methods: ["GET", "POST"],
110+
path: "{proxy+}",
125111
},
126-
entry: '../../src/handler.ts',
127-
functionName: `cmr-stac-api-${STAGE_NAME}`
112+
entry: "../../src/handler.ts",
113+
functionName: `cmr-stac-api-${STAGE_NAME}`,
128114
});
129115

130116
this.serviceEndpoint = [
131-
'https://',
117+
"https://",
132118
apiGatewayRestApi.ref,
133-
'.execute-api.',
119+
".execute-api.",
134120
this.region,
135-
'.',
121+
".",
136122
this.urlSuffix,
137123
`/${STAGE_NAME}`,
138-
].join('');
124+
].join("");
139125

140-
new cdk.CfnOutput(this, 'CfnOutputServiceEndpoint', {
141-
key: 'ServiceEndpoint',
142-
description: 'URL of the service endpoint',
126+
new cdk.CfnOutput(this, "CfnOutputServiceEndpoint", {
127+
key: "ServiceEndpoint",
128+
description: "URL of the service endpoint",
143129
exportName: `sls-${this.stackName}-ServiceEndpoint`,
144130
value: this.serviceEndpoint.toString(),
145131
});

cdk/cmr-stac-dev/test/cmr-stac-dev.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
// example test. To run these tests, uncomment this file along with the
66
// example resource in lib/cmr-stac-stack.ts
7-
test('SQS Queue Created', () => {
8-
// const app = new cdk.App();
9-
// // WHEN
10-
// const stack = new CmrStac.CmrStacStack(app, 'MyTestStack');
11-
// // THEN
12-
// const template = Template.fromStack(stack);
13-
14-
// template.hasResourceProperties('AWS::SQS::Queue', {
15-
// VisibilityTimeout: 300
16-
// });
7+
test("SQS Queue Created", () => {
8+
// const app = new cdk.App();
9+
// // WHEN
10+
// const stack = new CmrStac.CmrStacStack(app, 'MyTestStack');
11+
// // THEN
12+
// const template = Template.fromStack(stack);
13+
// template.hasResourceProperties('AWS::SQS::Queue', {
14+
// VisibilityTimeout: 300
15+
// });
1716
});

cdk/cmr-stac-dev/tsconfig.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
"compilerOptions": {
33
"target": "ES2020",
44
"module": "commonjs",
5-
"lib": [
6-
"es2020",
7-
"dom"
8-
],
5+
"lib": ["es2020", "dom"],
96
"declaration": true,
107
"strict": true,
118
"noImplicitAny": true,
@@ -20,12 +17,7 @@
2017
"inlineSources": true,
2118
"experimentalDecorators": true,
2219
"strictPropertyInitialization": false,
23-
"typeRoots": [
24-
"./node_modules/@types"
25-
]
20+
"typeRoots": ["./node_modules/@types"]
2621
},
27-
"exclude": [
28-
"node_modules",
29-
"cdk.out"
30-
]
22+
"exclude": ["node_modules", "cdk.out"]
3123
}

0 commit comments

Comments
 (0)