Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/core/src/awsService/appBuilder/activation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ async function registerAppBuilderCommands(context: ExtContext): Promise<void> {
}
}),
Commands.register({ id: 'aws.toolkit.lambda.createServerlessLandProject', autoconnect: false }, async () => {
await createNewServerlessLandProject(context)
await telemetry.lambda_createServerlessLandProject.run(async () => {
await createNewServerlessLandProject(context)
})
})
)
}
31 changes: 11 additions & 20 deletions packages/core/src/awsService/appBuilder/serverlessLand/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()
import * as path from 'path'
import * as vscode from 'vscode'
import { getTelemetryReason, getTelemetryResult } from '../../../shared/errors'
import { getLogger } from '../../../shared/logger/logger'
import { checklogs } from '../../../shared/localizedText'
import { Result, telemetry } from '../../../shared/telemetry/telemetry'
import { telemetry } from '../../../shared/telemetry/telemetry'
import { CreateServerlessLandWizardForm, CreateServerlessLandWizard } from './wizard'
import { ExtContext } from '../../../shared/extensions'
import { addFolderToWorkspace } from '../../../shared/utilities/workspaceUtils'
Expand All @@ -37,17 +36,13 @@ const serverlessLandRepo = 'serverless-patterns'
* 6. Handles errors and emits telemetry
*/
export async function createNewServerlessLandProject(extContext: ExtContext): Promise<void> {
let createResult: Result = 'Succeeded'
let reason: string | undefined
let metadataManager: MetadataManager

try {
metadataManager = MetadataManager.getInstance()
// Launch the project creation wizard
const config = await launchProjectCreationWizard(extContext)
if (!config) {
createResult = 'Cancelled'
reason = 'userCancelled'
return
}
const assetName = metadataManager.getAssetName(config.pattern, config.runtime, config.iac)
Expand All @@ -61,9 +56,12 @@ export async function createNewServerlessLandProject(extContext: ExtContext): Pr
},
true
)
telemetry.record({
templateName: assetName,
runtimeString: config.runtime,
iac: config.iac,
})
} catch (err) {
createResult = getTelemetryResult(err)
reason = getTelemetryReason(err)
getLogger().error(
localize(
'AWS.serverlessland.initWizard.general.error',
Expand All @@ -72,17 +70,10 @@ export async function createNewServerlessLandProject(extContext: ExtContext): Pr
)
)
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,
})
}
}

async function launchProjectCreationWizard(
export async function launchProjectCreationWizard(
extContext: ExtContext
): Promise<CreateServerlessLandWizardForm | undefined> {
const awsContext = extContext.awsContext
Expand All @@ -95,7 +86,7 @@ async function launchProjectCreationWizard(
}).run()
}

async function downloadPatternCode(config: CreateServerlessLandWizardForm, assetName: string): Promise<void> {
export async function downloadPatternCode(config: CreateServerlessLandWizardForm, assetName: string): Promise<void> {
const fullAssetName = assetName + '.zip'
const location = vscode.Uri.joinPath(config.location, config.name)
try {
Expand All @@ -108,7 +99,7 @@ async function downloadPatternCode(config: CreateServerlessLandWizardForm, asset
}
}

async function openReadmeFile(config: CreateServerlessLandWizardForm): Promise<void> {
export async function openReadmeFile(config: CreateServerlessLandWizardForm): Promise<void> {
try {
const readmeUri = await getProjectUri(config, readmeFile)
if (!readmeUri) {
Expand All @@ -123,12 +114,12 @@ async function openReadmeFile(config: CreateServerlessLandWizardForm): Promise<v
}
}

async function getProjectUri(
export async function getProjectUri(
config: Pick<CreateServerlessLandWizardForm, 'location' | 'name'>,
file: string
): Promise<vscode.Uri | undefined> {
if (!file) {
throw Error('expected "file" parameter to have at least one item')
throw new ToolkitError('expected "file" parameter to have at least one item')
}
const cfnTemplatePath = path.resolve(config.location.fsPath, config.name, file)
if (await fs.exists(cfnTemplatePath)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"patterns": {
"s3-lambda-resizing-sam": {
"Image Resizing": {
"name": "Resizing image",
"description": "Lambda, S3 • Python, Javascript, Java, .NET • SAM",
"implementation": [
Expand All @@ -26,7 +26,7 @@
}
]
},
"apigw-rest-api-lambda-sam": {
"Hello World Lambda with API": {
"name": "Rest API",
"description": "Lambda, API Gateway • Python, Javascript, Java, .NET • SAM",
"implementation": [
Expand All @@ -51,6 +51,32 @@
"assetName": "apigw-rest-api-lambda-dotnet"
}
]
},
"Process SQS Records with Lambda": {
"name": "Rest API",
"description": "Lambda, SQS • Python, Javascript, Java, .NET • SAM",
"implementation": [
{
"iac": "sam",
"runtime": "python",
"assetName": "sqs-lambda-python-sam"
},
{
"iac": "sam",
"runtime": "javascript",
"assetName": "sqs-lambda-nodejs-sam"
},
{
"iac": "sam",
"runtime": "java",
"assetName": "sqs-lambda-java-sam"
},
{
"iac": "sam",
"runtime": "dotnet",
"assetName": "sqs-lambda-dotnet-sam"
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import * as nodefs from 'fs' // eslint-disable-line no-restricted-imports
import * as path from 'path'
import { ToolkitError } from '../../../shared/errors'
import globals from '../../../shared/extensionGlobals'

Expand Down Expand Up @@ -48,7 +49,7 @@ export class MetadataManager {
}

public getMetadataPath(): string {
return globals.context.asAbsolutePath('dist/src/serverlessLand/metadata.json')
return globals.context.asAbsolutePath(path.join('dist', 'src', 'serverlessLand', 'metadata.json'))
Copy link
Contributor

@justinmk3 justinmk3 Mar 6, 2025

Choose a reason for hiding this comment

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

? Why is join() needed here? "/" slashes work just fine on Windows.

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface CreateServerlessLandWizardForm {
pattern: string
runtime: string
iac: string
assetName: string
}

function promptPattern(metadataManager: MetadataManager) {
Expand Down
Loading
Loading