Skip to content

Conversation

@mndeshmu97
Copy link

@mndeshmu97 mndeshmu97 commented Mar 25, 2025

Description

  • Post-startup script stored in SMD (SageMaker Distribution) enables the required customizations for SMUS applications.
  • This functionality is currently operational for JupyterLab apps
  • We are extending this capability to CodeEditor apps

Testing Done

  • Tested building the local image for these changes and tested on personal LL stack using BYOI
  • Verified script execution logs file generation at /var/log/apps after app launch

Issue #, if available:

Description of changes:

  • Adding /api/poststartup endpoint for the SageMaker Unified Studio user case that runs the post startup script.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

return this._handleWebExtensionResource(req, res, parsedUrl);
}
+ if (pathname === this._postStartupScriptRoute) {
+ return this._handlePostStartupScriptInvocation(req, res);

Choose a reason for hiding this comment

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

Spacing seems to be off here.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed in latest commit

res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ 'success': 'true' }));
} else {
serveError(req, res, 404, 'Poststartup script file not found at ' + postStartupScripPath);

Choose a reason for hiding this comment

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

Wld this block anything on the HostAgent?

Copy link
Author

Choose a reason for hiding this comment

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

HostAgent will handle all non-OK (non-200) responses and will not cause the app to fail.
I am adding that change in LLHA to handle NonOKResponse.


res.statusCode = 200;
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ 'success': 'true' }));

Choose a reason for hiding this comment

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

Are we expecting the success value as boolean or string? This is giving as string value true

Copy link
Author

@mndeshmu97 mndeshmu97 Mar 25, 2025

Choose a reason for hiding this comment

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

I can change this to boolean true, but we dont use it.

Choose a reason for hiding this comment

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

Lets follow the norm that we use in JL IDE.

}
if (pathname === this._postStartupScriptRoute) {
return this._handlePostStartupScriptInvocation(req, res);
}

Choose a reason for hiding this comment

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

Spacing issue on line 155.

}
+ if (pathname === this._postStartupScriptRoute) {
+ return this._handlePostStartupScriptInvocation(req, res);
+ }

Choose a reason for hiding this comment

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

Spacing issue.

/**
* Handles API requests to run the post-startup script in SMD.
*/
private async _handlePostStartupScriptInvocation(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {

Choose a reason for hiding this comment

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

Hey Mrunal - just thinking - i dont think we should even run through this function for SM AI side. Using the Env variable - lets restrict this SMUS only.

}
if (pathname === this._postStartupScriptRoute) {
// Only trigger post-startup script invocation for SageMakerUnifiedStudio app.
if (process.env['SERVICE_NAME'] != 'SageMakerUnifiedStudio') {

Choose a reason for hiding this comment

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

We shld handle this in _handlePostStartupScriptInvocation method.

@aws-asolidu
Copy link
Contributor

aws-asolidu commented Mar 27, 2025

Description

  • Post-startup script stored in SMD (SageMaker Distribution) enables the required customizations for SMUS applications.
  • This functionality is currently operational for JupyterLab apps
  • We are extending this capability to CodeEditor apps

Testing Done

Issue #, if available:

Description of changes:

  • Adding /api/poststartup endpoint for the SageMaker Unified Studio user case that runs the post startup script.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Thanks for the thorough testing.
btw because this is an open source project, we shouldn't be linking to internal links.

const logStream = fs.createWriteStream(logPath, { flags: 'a' });

// Only trigger post-startup script invocation for SageMakerUnifiedStudio app.
if (process.env['SERVICE_NAME'] != 'SageMakerUnifiedStudio') {
Copy link
Contributor

Choose a reason for hiding this comment

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

make constant or enum SageMakerUnifiedStudio. Also I think this check should be lifted into the handle function.

Choose a reason for hiding this comment

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

I would like to keep it in specific function to handle the use cases as needed than in handle function whose only thing is to route the request itself.


// Only trigger post-startup script invocation for SageMakerUnifiedStudio app.
if (process.env['SERVICE_NAME'] != 'SageMakerUnifiedStudio') {
return serveError(req, res, 400, 'Bad request.');
Copy link
Contributor

Choose a reason for hiding this comment

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

400 is for malformed requests, this should be 403 forbidden with message like "This API is only accessible to Maxdome clients"

Choose a reason for hiding this comment

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

Make sense. We can keep it simple 403 with message as Forbidden

res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ 'success': 'true' }));
} else {
serveError(req, res, 404, 'Poststartup script file not found at ' + postStartupScripPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

404 is for if the file is part of the API url path and client is explicitly requesting it. This should be 500 internal error.

// Adding 0o755 to make script file executable
fs.chmodSync(postStartupScripPath, 0o755);

const subprocess = spawn('bash', [`${postStartupScripPath}`], { cwd: '/' });
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a public link where we can view this script? I don't have access to the link in the description.

Copy link
Author

Choose a reason for hiding this comment

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

No, its in our private SMD repo

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.

3 participants