Skip to content

Commit fbde6bf

Browse files
committed
fix(examples): rename function names to match integration-test.js script
1 parent c4af3ff commit fbde6bf

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

packages/aws-durable-execution-sdk-js-examples/scripts/generate-sam-template.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ function toPascalCase(filename) {
4545
* Get TypeScript files from src/examples directory
4646
*/
4747
function getExampleFiles() {
48-
const examplesDir = path.join(__dirname, "../src/examples");
48+
const catalogPath = path.join(
49+
__dirname,
50+
"../src/utils/examples-catalog.json",
51+
);
4952

50-
if (!fs.existsSync(examplesDir)) {
51-
throw new Error(`Examples directory not found: ${examplesDir}`);
53+
if (!fs.existsSync(catalogPath)) {
54+
throw new Error(`Examples directory not found: ${catalogPath}`);
5255
}
5356

54-
const exampleFiles = [];
57+
const catalog = JSON.parse(fs.readFileSync(catalogPath, "utf8"));
58+
59+
const exampleFiles = catalog.map((example) => example.name);
5560

5661
// Read all directories in examples
5762
const entries = fs.readdirSync(examplesDir, { withFileTypes: true });
@@ -105,25 +110,25 @@ function getExampleFiles() {
105110
/**
106111
* Create a Lambda function resource configuration
107112
*/
108-
function createFunctionResource(filename, skipVerboseLogging = false) {
109-
const resourceName = toPascalCase(filename);
110-
const config = EXAMPLE_CONFIGS[filename] || DEFAULT_CONFIG;
113+
function createFunctionResource(
114+
resourceName,
115+
catalog,
116+
skipVerboseLogging = false,
117+
) {
118+
const config = EXAMPLE_CONFIGS[resourceName] || DEFAULT_CONFIG;
111119

112120
const functionResource = {
113121
Type: "AWS::Serverless::Function",
114122
Properties: {
115-
FunctionName: `${resourceName}-TypeScript`,
123+
FunctionName: resourceName,
116124
CodeUri: "./dist",
117-
Handler: `${filename}.handler`,
125+
Handler: catalog.handler,
118126
Runtime: "nodejs22.x",
119127
Architectures: ["x86_64"],
120128
MemorySize: config.memorySize,
121129
Timeout: config.timeout,
122130
Role: { "Fn::GetAtt": ["DurableFunctionRole", "Arn"] },
123-
DurableConfig: {
124-
ExecutionTimeout: 3600,
125-
RetentionPeriodInDays: 7,
126-
},
131+
DurableConfig: catalog.durableConfig,
127132
Environment: {
128133
Variables: {
129134
AWS_ENDPOINT_URL_LAMBDA: "http://host.docker.internal:5000",
@@ -149,9 +154,20 @@ function createFunctionResource(filename, skipVerboseLogging = false) {
149154
* Generate the complete CloudFormation template
150155
*/
151156
function generateTemplate(skipVerboseLogging = false) {
152-
const exampleFiles = getExampleFiles();
157+
const examplesCatalogPath = path.join(
158+
__dirname,
159+
"../src/utils/examples-catalog.json",
160+
);
161+
162+
if (!fs.existsSync(examplesCatalogPath)) {
163+
throw new Error(`Examples directory not found: ${examplesCatalogPath}`);
164+
}
165+
166+
const examplesCatalog = JSON.parse(
167+
fs.readFileSync(examplesCatalogPath, "utf8"),
168+
);
153169

154-
if (exampleFiles.length === 0) {
170+
if (examplesCatalog.length === 0) {
155171
throw new Error("No TypeScript example files found in src/examples");
156172
}
157173

@@ -202,12 +218,11 @@ function generateTemplate(skipVerboseLogging = false) {
202218
};
203219

204220
// Generate resources for each example file
205-
exampleFiles.forEach((filename) => {
206-
const resourceName = toPascalCase(filename);
207-
template.Resources[resourceName] = createFunctionResource(
208-
filename,
209-
skipVerboseLogging,
210-
);
221+
examplesCatalog.forEach((catalog) => {
222+
const resourceName = catalog.name.replace(/\s/g, "") + `-22x-NodeJS-Local`;
223+
template.Resources[
224+
toPascalCase(catalog.handler.slice(0, -".handler".length))
225+
] = createFunctionResource(resourceName, catalog, skipVerboseLogging);
211226
});
212227

213228
return template;

packages/aws-durable-execution-sdk-js-examples/src/__tests__/generate-sam-template.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe("generate-sam-template", () => {
2929
});
3030

3131
test("creates function resource with custom config for steps-with-retry", () => {
32-
const resource = createFunctionResource("steps-with-retry");
32+
const resource = createFunctionResource("steps-with-retry", {});
3333

3434
expect(resource.Properties.FunctionName).toBe(
3535
"StepsWithRetry-TypeScript",
@@ -46,7 +46,16 @@ describe("generate-sam-template", () => {
4646
});
4747

4848
test("includes required environment variables", () => {
49-
const resource = createFunctionResource("hello-world");
49+
const resource = createFunctionResource("hello-world", {});
50+
51+
expect(resource.Properties.Environment.Variables).toEqual({
52+
AWS_ENDPOINT_URL_LAMBDA: "http://host.docker.internal:5000",
53+
DURABLE_VERBOSE_MODE: "true",
54+
});
55+
});
56+
57+
test("disables verbose logging when skipVerboseLogging is true", () => {
58+
const resource = createFunctionResource("hello-world", {}, true);
5059

5160
expect(resource.Properties.Environment.Variables).toEqual({
5261
AWS_ENDPOINT_URL_LAMBDA: "http://host.docker.internal:5000",

0 commit comments

Comments
 (0)