Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
Regression where any Date
sent in ValidFrom/ValidUntil causes an error to be thrown. The crash is reported by the server and seems to be related to the milliseconds.
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/client-ec2@npm:3.817.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
18.20.4
Reproduction Steps
Note that I've redacted some things.
yarn add @aws-sdk/client-ec2
// test.js
import { EC2Client, RequestSpotFleetCommand } from '@aws-sdk/client-ec2';
const client = new EC2Client({ region: 'us-east-1' });
const dryRun = false;
await client.send(new RequestSpotFleetCommand({
DryRun: dryRun,
SpotFleetRequestConfig: {
IamFleetRole: 'arn:aws:iam::REDACTED',
AllocationStrategy: 'capacityOptimized',
TargetCapacity: 1,
ValidUntil: new Date(Date.now() + (1000 * 60 * 60)),
TerminateInstancesWithExpiration: true,
Type: 'maintain',
TargetCapacityUnitType: 'units',
LaunchSpecifications: [
{
ImageId: 'ami-REDACTED',
BlockDeviceMappings: [
{
DeviceName: '/dev/sda1',
Ebs: {
DeleteOnTermination: true,
VolumeType: 'gp2',
VolumeSize: 8,
SnapshotId: 'snap-REDACTED',
},
},
],
IamInstanceProfile: {
Arn: 'arn:aws:iam::REDACTED',
},
KeyName: 'REDACTED',
SecurityGroups: [
{
GroupId: 'sg-REDACTED',
},
],
UserData: 'REDACTED',
InstanceRequirements: {
VCpuCount: {
Min: 8,
Max: 8,
},
MemoryMiB: {
Min: 4096,
},
SpotMaxPricePercentageOverLowestPrice: 100,
},
},
],
},
}));
node test.js
Note the ValidUntil
prop.
Observed Behavior
node_modules/@smithy/smithy-client/dist-cjs/index.js:379
const response = new exceptionCtor({
^
InvalidSpotFleetRequestConfig: Parameter: SpotFleetRequestConfig.ValidUntil is invalid.
at throwDefaultError (node_modules/@smithy/smithy-client/dist-cjs/index.js:379:20)
at node_modules/@smithy/smithy-client/dist-cjs/index.js:388:5
at de_CommandError (node_modules/@aws-sdk/client-ec2/dist-cjs/index.js:17188:10)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async node_modules/@smithy/middleware-serde/dist-cjs/index.js:36:20
at async node_modules/@smithy/core/dist-cjs/index.js:193:18
at async node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38
at async node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22
at <anonymous> (test.ts:5:18) {
'$fault': 'client',
'$metadata': {
httpStatusCode: 400,
requestId: '0856c9e6-159e-482c-8c2b-ee3fa2965def',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
Code: 'InvalidSpotFleetRequestConfig'
}
Expected Behavior
It should start the fleet request.
Possible Solution
Must support Date
in ValidFrom/ValidUntil (as the typescript definitions suggests).
Additional Information/Context
Note that:
- If I set dryRun to true, it doesn't error.
- If I downgrade to @aws-sdk/client-ec2 3.427.0 it works.
- If I change
ValidUntil
to{ toISOString: () => new Date(Date.now() + (1000 * 60 * 60)).toISOString().replace(/\.\d+Z$/, 'Z') }
it works.
This suggests that the @aws-sdk/client-ec2
client calls Date.toISOString()
on ValidFrom/ValidUntil and then sends to the server what is returned from those (e.g. 2025-05-26T21:37:50.051Z
), however the server expects 2025-05-26T21:37:50Z
(no milliseconds).
How am I the only person who seems to have hit this obvious bug in the JS SDK?
Related: boto/boto3#714