Skip to content

Commit

Permalink
Merge branch 'main' into dependabot-version-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual committed Dec 20, 2024
2 parents bc872ff + b574bce commit 6f17062
Show file tree
Hide file tree
Showing 31 changed files with 384 additions and 56 deletions.
6 changes: 0 additions & 6 deletions .changeset/itchy-flowers-reply.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/old-hornets-type.md

This file was deleted.

2 changes: 0 additions & 2 deletions .changeset/plenty-mugs-learn.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/swift-mirrors-enjoy.md

This file was deleted.

1 change: 1 addition & 0 deletions .eslint_dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"hotswappable",
"hotswapped",
"hotswapping",
"href",
"iamv2",
"identitypool",
"idps",
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/health_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ on:
description: 'Node versions list (as JSON array).'
required: false
type: string
default: '["18", "20"]'
default: '["18", "20", "22"]'
workflow_call:
inputs:
desired-cdk-version:
Expand Down Expand Up @@ -78,7 +78,7 @@ on:
description: 'Node versions list (as JSON array).'
required: false
type: string
default: '["18", "20"]'
default: '["18", "20", "22"]'

env:
# Health checks can run on un-released code. Often work in progress.
Expand Down Expand Up @@ -121,7 +121,7 @@ jobs:
echo "os=$os" >> "$GITHUB_OUTPUT"
echo "os_for_e2e=$os_for_e2e" >> "$GITHUB_OUTPUT"
if [ -z "${{ inputs.node }}" ]; then
echo 'node=["18", "20"]' >> "$GITHUB_OUTPUT"
echo 'node=["18", "20", "22"]' >> "$GITHUB_OUTPUT"
else
echo 'node=${{ inputs.node }}' >> "$GITHUB_OUTPUT"
fi
Expand Down Expand Up @@ -512,6 +512,10 @@ jobs:
node-version: 20
- os: windows-latest
node-version: 20
- os: macos-14
node-version: 22
- os: windows-latest
node-version: 22
runs-on: ${{ matrix.os }}
timeout-minutes: ${{ matrix.os == 'windows-latest' && 35 || 25 }}
needs:
Expand All @@ -538,7 +542,7 @@ jobs:
matrix:
os: ${{ fromJSON(needs.resolve_inputs.outputs.os) }}
pkg-manager: [npm, yarn-classic, yarn-modern, pnpm]
node-version: ['20']
node-version: ['22']
env:
PACKAGE_MANAGER: ${{ matrix.pkg-manager }}
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"test": "npm run test:dir $(tsx scripts/get_unit_test_dir_list.ts)",
"test:coverage:generate": "NODE_V8_COVERAGE=coverage/ npm run test",
"test:coverage:threshold": "c8 npm run test",
"test:dir": "tsx --test --test-reporter spec",
"test:dir": "tsx scripts/run_tests.ts",
"test:scripts": "npm run test:dir $(glob --cwd=scripts --absolute **/*.test.ts)",
"update:api": "tsx scripts/concurrent_workspace_script.ts update:api --if-present",
"update:tsconfig-refs": "tsx scripts/update_tsconfig_refs.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/ai-constructs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type ConversationHandlerFunctionProps = {
region?: string;
}>;
memoryMB?: number;
timeoutSeconds?: number;
logging?: {
level?: ApplicationLogLevel;
retention?: RetentionDays;
Expand Down
6 changes: 6 additions & 0 deletions packages/ai-constructs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @aws-amplify/ai-constructs

## 1.2.0

### Minor Changes

- a66f5f2: Expose timeout property

## 1.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ai-constructs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/ai-constructs",
"version": "1.1.0",
"version": "1.2.0",
"type": "commonjs",
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,68 @@ void describe('Conversation Handler Function construct', () => {
});
});

void describe('timeout property', () => {
void it('sets valid timeout', () => {
const app = new App();
const stack = new Stack(app);
new ConversationHandlerFunction(stack, 'conversationHandler', {
models: [],
timeoutSeconds: 124,
});
const template = Template.fromStack(stack);

template.hasResourceProperties('AWS::Lambda::Function', {
Timeout: 124,
});
});

void it('sets default timeout', () => {
const app = new App();
const stack = new Stack(app);
new ConversationHandlerFunction(stack, 'conversationHandler', {
models: [],
});
const template = Template.fromStack(stack);

template.hasResourceProperties('AWS::Lambda::Function', {
Timeout: 60,
});
});

void it('throws on timeout below 1', () => {
assert.throws(() => {
const app = new App();
const stack = new Stack(app);
new ConversationHandlerFunction(stack, 'conversationHandler', {
models: [],
timeoutSeconds: 0,
});
}, new Error('timeoutSeconds must be a whole number between 1 and 900 inclusive'));
});

void it('throws on timeout above 15 minutes', () => {
assert.throws(() => {
const app = new App();
const stack = new Stack(app);
new ConversationHandlerFunction(stack, 'conversationHandler', {
models: [],
timeoutSeconds: 60 * 15 + 1,
});
}, new Error('timeoutSeconds must be a whole number between 1 and 900 inclusive'));
});

void it('throws on fractional memory', () => {
assert.throws(() => {
const app = new App();
const stack = new Stack(app);
new ConversationHandlerFunction(stack, 'conversationHandler', {
models: [],
memoryMB: 256.2,
});
}, new Error('memoryMB must be a whole number between 128 and 10240 inclusive'));
});
});

void describe('logging options', () => {
void it('sets log level', () => {
const app = new App();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export type ConversationHandlerFunctionProps = {
*/
memoryMB?: number;

/**
* An amount of time in seconds between 1 second and 15 minutes.
* Must be a whole number.
* Default is 60 seconds.
*/
timeoutSeconds?: number;

logging?: {
level?: ApplicationLogLevel;
retention?: RetentionDays;
Expand Down Expand Up @@ -96,7 +103,7 @@ export class ConversationHandlerFunction
`conversationHandlerFunction`,
{
runtime: LambdaRuntime.NODEJS_18_X,
timeout: Duration.seconds(60),
timeout: Duration.seconds(this.resolveTimeout()),
entry: this.props.entry ?? defaultHandlerFilePath,
handler: 'handler',
memorySize: this.resolveMemory(),
Expand Down Expand Up @@ -185,6 +192,28 @@ export class ConversationHandlerFunction
}
return this.props.memoryMB;
};

private resolveTimeout = () => {
const timeoutMin = 1;
const timeoutMax = 60 * 15; // 15 minutes in seconds
const timeoutDefault = 60;
if (this.props.timeoutSeconds === undefined) {
return timeoutDefault;
}

if (
!isWholeNumberBetweenInclusive(
this.props.timeoutSeconds,
timeoutMin,
timeoutMax
)
) {
throw new Error(
`timeoutSeconds must be a whole number between ${timeoutMin} and ${timeoutMax} inclusive`
);
}
return this.props.timeoutSeconds;
};
}

const isWholeNumberBetweenInclusive = (
Expand Down
1 change: 1 addition & 0 deletions packages/backend-ai/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type DefineConversationHandlerFunctionProps = {
region?: string;
}>;
memoryMB?: number;
timeoutSeconds?: number;
logging?: ConversationHandlerFunctionLoggingOptions;
};

Expand Down
11 changes: 11 additions & 0 deletions packages/backend-ai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @aws-amplify/backend-ai

## 1.2.0

### Minor Changes

- a66f5f2: Expose timeout property

### Patch Changes

- Updated dependencies [a66f5f2]
- @aws-amplify/ai-constructs@1.2.0

## 1.1.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws-amplify/backend-ai",
"version": "1.1.0",
"version": "1.2.0",
"type": "module",
"publishConfig": {
"access": "public"
Expand All @@ -22,7 +22,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@aws-amplify/ai-constructs": "^1.1.0",
"@aws-amplify/ai-constructs": "^1.2.0",
"@aws-amplify/backend-output-schemas": "^1.4.0",
"@aws-amplify/backend-output-storage": "^1.1.4",
"@aws-amplify/data-schema-types": "^1.2.0",
Expand Down
50 changes: 50 additions & 0 deletions packages/backend-ai/src/conversation/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { customEntryHandler } from './test-assets/with-custom-entry/resource.js'
import { Template } from 'aws-cdk-lib/assertions';
import { defineConversationHandlerFunction } from './factory.js';
import { ConversationHandlerFunction } from '@aws-amplify/ai-constructs/conversation';
import { AmplifyError } from '@aws-amplify/platform-core';

const createStackAndSetContext = (): Stack => {
const app = new App();
Expand Down Expand Up @@ -204,6 +205,55 @@ void describe('ConversationHandlerFactory', () => {
});
});

void it('maps invalid memory error', () => {
const factory = defineConversationHandlerFunction({
entry: './test-assets/with-default-entry/handler.ts',
name: 'testHandlerName',
models: [],
memoryMB: -1,
});
assert.throws(
() => factory.getInstance(getInstanceProps),
(error: Error) => {
assert.ok(AmplifyError.isAmplifyError(error));
assert.strictEqual(error.name, 'InvalidMemoryMBError');
return true;
}
);
});

void it('passes timeout setting to construct', () => {
const factory = defineConversationHandlerFunction({
entry: './test-assets/with-default-entry/handler.ts',
name: 'testHandlerName',
models: [],
timeoutSeconds: 124,
});
const lambda = factory.getInstance(getInstanceProps);
const template = Template.fromStack(Stack.of(lambda.resources.lambda));
template.resourceCountIs('AWS::Lambda::Function', 1);
template.hasResourceProperties('AWS::Lambda::Function', {
Timeout: 124,
});
});

void it('maps invalid timeout error', () => {
const factory = defineConversationHandlerFunction({
entry: './test-assets/with-default-entry/handler.ts',
name: 'testHandlerName',
models: [],
timeoutSeconds: -1,
});
assert.throws(
() => factory.getInstance(getInstanceProps),
(error: Error) => {
assert.ok(AmplifyError.isAmplifyError(error));
assert.strictEqual(error.name, 'InvalidTimeoutError');
return true;
}
);
});

void it('passes log level to construct', () => {
const factory = defineConversationHandlerFunction({
entry: './test-assets/with-default-entry/handler.ts',
Expand Down
Loading

0 comments on commit 6f17062

Please sign in to comment.