-
Notifications
You must be signed in to change notification settings - Fork 749
feat(lambda): Building Quick Pick structure and Entrypoints #6592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jpinkney-aws
merged 6 commits into
aws:feature/serverlessland
from
Vandita2020:entrypoints
Feb 20, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e2ebad
Building Quick Pick structure
11b3098
Arranging file structure
891cea4
Adding entrypoint to Lambda Section in Explorer
cf4928f
Entrypoint from Getting started walkthrough link
eccc7bd
Review revision
8381db4
Review changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/core/src/awsService/appBuilder/serverlessLand/main.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import * as nls from 'vscode-nls' | ||
| const localize = nls.loadMessageBundle() | ||
| import * as path from 'path' | ||
| import { getTelemetryReason, getTelemetryResult } from '../../../shared/errors' | ||
| import { getLogger } from '../../../shared/logger/logger' | ||
| import globals from '../../../shared/extensionGlobals' | ||
| import { checklogs } from '../../../shared/localizedText' | ||
| import { Result, telemetry } from '../../../shared/telemetry/telemetry' | ||
| import { CreateServerlessLandWizard } from './wizard' | ||
| import { ExtContext } from '../../../shared/extensions' | ||
| import { addFolderToWorkspace } from '../../../shared/utilities/workspaceUtils' | ||
|
|
||
| export const readmeFile: string = 'README.md' | ||
|
|
||
| /** | ||
| * Creates a new Serverless Land project using the provided extension context | ||
| * @param extContext Extension context containing AWS credentials and region information | ||
| * @returns Promise that resolves when the project creation is complete | ||
| * | ||
| * This function: | ||
| * 1. Validates AWS credentials and regions | ||
| * 2. Launches the Serverless Land project creation wizard | ||
| * 3. Creates the project structure | ||
| * 4. Adds the project folder to the workspace | ||
| * 5. Opens the README.md file if available | ||
| * 6. Handles errors and emits telemetry | ||
| */ | ||
| export async function createNewServerlessLandProject(extContext: ExtContext): Promise<void> { | ||
| const awsContext = extContext.awsContext | ||
| let createResult: Result = 'Succeeded' | ||
| let reason: string | undefined | ||
|
|
||
| try { | ||
| const credentials = await awsContext.getCredentials() | ||
| const defaultRegion = awsContext.getCredentialDefaultRegion() | ||
|
|
||
| // Launch the project creation wizard | ||
| const config = await new CreateServerlessLandWizard({ | ||
| credentials, | ||
| defaultRegion, | ||
| }).run() | ||
| if (!config) { | ||
| createResult = 'Cancelled' | ||
| reason = 'userCancelled' | ||
| return | ||
| } | ||
|
|
||
| // Add the project folder to the workspace | ||
| await addFolderToWorkspace( | ||
| { | ||
| uri: config.location, | ||
| name: path.basename(config.location.fsPath), | ||
| }, | ||
| true | ||
| ) | ||
| } catch (err) { | ||
| createResult = getTelemetryResult(err) | ||
| reason = getTelemetryReason(err) | ||
|
|
||
| globals.outputChannel.show(true) | ||
| getLogger().error( | ||
| localize( | ||
| 'AWS.serverlessland.initWizard.general.error', | ||
| 'Error creating new Serverless Land Application. {0}', | ||
| checklogs() | ||
| ) | ||
| ) | ||
| getLogger().error('Error creating new Serverless Land Application: %O', err as Error) | ||
| } finally { | ||
| // add telemetry | ||
| // TODO: Will add telemetry once the implementation gets completed | ||
| telemetry.sam_init.emit({ | ||
| result: createResult, | ||
| reason: reason, | ||
| }) | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
packages/core/src/awsService/appBuilder/serverlessLand/metadata.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| { | ||
| "patterns": { | ||
| "s3-lambda-resizing-sam": { | ||
| "name": "Resizing image", | ||
| "description": "Lambda, S3 • Python, Javascript, Java, .NET • SAM", | ||
| "runtimes": [ | ||
| { | ||
| "id": "python", | ||
| "name": "Python" | ||
| }, | ||
| { | ||
| "id": "javascript", | ||
| "name": "Javascript" | ||
| }, | ||
| { | ||
| "id": "dotnet", | ||
| "name": "Dotnet" | ||
| }, | ||
| { | ||
| "id": "java", | ||
| "name": "Java" | ||
| } | ||
| ], | ||
| "iac": [ | ||
| { | ||
| "id": "sam", | ||
| "name": "SAM" | ||
| } | ||
| ] | ||
| }, | ||
| "apigw-rest-api-lambda-sam": { | ||
| "name": "Rest API", | ||
| "description": "Lambda, API Gateway • Python, Javascript, Java, .NET • SAM", | ||
| "runtimes": [ | ||
| { | ||
| "id": "python", | ||
| "name": "Python" | ||
| }, | ||
| { | ||
| "id": "javascript", | ||
| "name": "Javascript" | ||
| }, | ||
| { | ||
| "id": "dotnet", | ||
| "name": "Dotnet" | ||
| }, | ||
| { | ||
| "id": "java", | ||
| "name": "Java" | ||
| } | ||
| ], | ||
| "iac": [ | ||
| { | ||
| "id": "sam", | ||
| "name": "AWS SAM" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| } |
121 changes: 121 additions & 0 deletions
121
packages/core/src/awsService/appBuilder/serverlessLand/metadataManager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /*! | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports | ||
| import { ToolkitError } from '../../../shared/errors' | ||
|
|
||
| interface IaC { | ||
| id: string | ||
| name: string | ||
| } | ||
| interface Runtime { | ||
| id: string | ||
| name: string | ||
| version: string | ||
| } | ||
| interface PatternData { | ||
| name: string | ||
| description: string | ||
| runtimes: Runtime[] | ||
| iac: IaC[] | ||
| } | ||
|
|
||
| export interface ProjectMetadata { | ||
| patterns: Record<string, PatternData> | ||
| } | ||
|
|
||
| /** | ||
| * Manages metadata for serverless application patterns | ||
| */ | ||
|
|
||
| export class MetadataManager { | ||
| private static instance: MetadataManager | ||
| private metadata: ProjectMetadata | undefined | ||
|
|
||
| private constructor() {} | ||
|
|
||
| public static getInstance(): MetadataManager { | ||
| if (!MetadataManager.instance) { | ||
| MetadataManager.instance = new MetadataManager() | ||
| } | ||
| return MetadataManager.instance | ||
| } | ||
|
|
||
| /** | ||
| * Loads metadata from a JSON file | ||
| * @param metadataPath Path to the metadata JSON file | ||
| * @returns Promise containing the parsed ProjectMetadata | ||
| */ | ||
| public async loadMetadata(metadataPath: string): Promise<ProjectMetadata> { | ||
| try { | ||
| if (!this.metadata) { | ||
| const metadataContent = nodefs.readFileSync(metadataPath, { encoding: 'utf-8' }) | ||
| const parseMetadata = JSON.parse(metadataContent) as ProjectMetadata | ||
| this.metadata = parseMetadata | ||
| } | ||
| return this.metadata | ||
| } catch (err) { | ||
| throw new ToolkitError(`Failed to load metadata: ${err instanceof Error ? err.message : String(err)}`) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves available patterns with their descriptions | ||
| * @returns Array of pattern objects containing labels and descriptions | ||
| */ | ||
| public getPatterns(): { label: string; description?: string }[] { | ||
| if (!this.metadata) { | ||
| return [] | ||
| } | ||
| return Object.entries(this.metadata.patterns).map(([patternName, patternData]) => { | ||
| let description: string | undefined = undefined | ||
| if (typeof patternData === 'string') { | ||
| description = patternData | ||
| } else if (Array.isArray(patternData)) { | ||
| // If description is an array, join it into a single string | ||
| description = patternData.join(' ') | ||
| } | ||
| if (!patternData || !patternData.name) { | ||
| return { | ||
| label: patternName, | ||
| description: description || 'No description available', | ||
| } | ||
| } | ||
| return { | ||
| label: patternName, | ||
| description: patternData.description, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Gets available runtimes for a specific pattern | ||
| * @param pattern The pattern name to get runtimes for | ||
| * @returns Array of runtime options with labels | ||
| */ | ||
| public getRuntimes(pattern: string): { label: string }[] { | ||
| const patternData = this.metadata?.patterns?.[pattern] | ||
| if (!patternData || !patternData.runtimes) { | ||
| return [] | ||
| } | ||
| return patternData.runtimes.map((runtime) => ({ | ||
| label: runtime.name, | ||
| })) | ||
| } | ||
|
|
||
| /** | ||
| * Gets available Infrastructure as Code options for a specific pattern | ||
| * @param pattern The pattern name to get IaC options for | ||
| * @returns Array of IaC options with labels | ||
| */ | ||
| public getIacOptions(pattern: string): { label: string }[] { | ||
| const patternData = this.metadata?.patterns?.[pattern] | ||
| if (!patternData || !patternData.iac) { | ||
| return [] | ||
| } | ||
| return patternData.iac.map((iac) => ({ | ||
| label: iac.name, | ||
| })) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.