Skip to content

Conversation

@htranho
Copy link
Contributor

@htranho htranho commented Aug 27, 2025

Overview

What is the feature?

Add LocalStack and Offline Lambda Support for Local Development

What is the Solution?

Add LocalStack and Offline Lambda Support for Local Development

What areas of the application does this impact?

Application run in local mode.

Testing

  1. To startup rdf4j, cdk synth and sam client: 'npm run start-local'
  2. Test all interfaces listed (http://localhost:3013/), specially the write interfaces, for example create a new scheme. Local mode should not required token.

Attachments

N/A

Checklist

  • I have added automated tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@htranho htranho marked this pull request as draft August 27, 2025 18:11
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (KMS-570@956a3fe). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             KMS-570      #74   +/-   ##
==========================================
  Coverage           ?   99.57%           
==========================================
  Files              ?      139           
  Lines              ?     2333           
  Branches           ?      571           
==========================================
  Hits               ?     2323           
  Misses             ?        9           
  Partials           ?        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

README.md Outdated
To run cdk synth:
```
CMR_BASE_URL=https://cmr.earthdata.nasa.gov RDF4J_SERVICE_URL=http://localhost:8080 npm run offline
npm run run-synth
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed if you are doing it below: cdk synth --context useLocalstack=true --output ./cdk.out > /dev/null 2>&1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, that is not needed because included in 'npm run start-local'. Is there a use case for just run 'cdk synth'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, removed that instruction.

npm run rdf4j:start
# Wait for rdf4j server to start
sleep 10
npm run rdf4j:setup
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think starting the db should be part of start-local. You might want to start-local multiple times and keep the data in the rdfdb.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, removed steps to startup and setup rdf4j.

import * as iam from 'aws-cdk-lib/aws-iam'
import * as lambda from 'aws-cdk-lib/aws-lambda'
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'
import * as nodejsLambda from 'aws-cdk-lib/aws-lambda-nodejs'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can also do:
import { NodejsFunction, NodejsFunctionProps } from 'aws-cdk-lib/aws-lambda-nodejs'
which I think it preferred way of doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

})
environment: this.props.environment,
// Conditionally add VPC configuration
...(this.props.useLocalstack ? {} : {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure useLocalstack from props

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

scope: Construct,
authorizerLambda: lambda.Function
): apigateway.IAuthorizer {
if (this.props.useLocalstack) {
Copy link
Contributor

@cgokey cgokey Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@htranho htranho marked this pull request as ready for review August 27, 2025 20:12
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION
}
const useLocalstack = app.node.tryGetContext('useLocalstack') === 'true'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const useLocalstack = app.node.tryGetContext('useLocalstack')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would not work in case user wanted useLocalstack to be false. So I fix this way and checked in:
keep 'const useLocalstack = app.node.tryGetContext('useLocalstack') === 'true' '
but in the start-local.sh change to 'cdk synth --context useLocalstack='true' --output ./cdk.out > /dev/null 2>&1'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was 'cdk synth --context useLocalstack=true --output ./cdk.out > /dev/null 2>&1'

@eudoroolivares2016
Copy link

So we'll want npm install aws-cdk --save-dev that will add the cdk lib to the dev dependencies which will allow us to build the template file/cdk.out directory

@htranho
Copy link
Contributor Author

htranho commented Aug 28, 2025

So we'll want npm install aws-cdk --save-dev that will add the cdk lib to the dev dependencies which will allow us to build the template file/cdk.out directory

Done.

@htranho htranho merged commit 2001257 into KMS-570 Sep 2, 2025
6 checks passed
@htranho htranho deleted the KMS-565 branch September 2, 2025 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants