aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
issue with aws service discovery javascript
Im developing a nodejs application that needs to register to the AWS service discovery on the app start. I'm using the @aws-sdk/client-servicediscovery lib in my node application. As a reference, I am using the code from here: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-servicediscovery/index.html.
const { ServiceDiscoveryClient, CreateHttpNamespaceCommand } = require("@aws-sdk/client-servicediscovery");
const client = new ServiceDiscoveryClient({ region: "xxx" });
const params = {
"ServiceId":"xxx",
"InstanceId":"xxx",
"CreatorRequestId":new Date(new Date().toUTCString()),
"Attributes": {
AWS_INSTANCE_IPV4: "xxx.xx.xx.xx",
AWS_INSTANCE_PORT: xxx,
service: "xxx",
}
};
const command = new CreateHttpNamespaceCommand(params);
client.send(command).then(
(data) => {
console.log(data)
},
(error) => {
console.log(error)
}
);
While running the app, getting these errors.
/application/node_modules/@aws-sdk/shared-ini-file-loader/dist-cjs/slurpFile.js:5
const { readFile } = fs_1.promises;
^
TypeError: Cannot destructure property `readFile` of 'undefined' or 'null'.
at Object.<anonymous> (/application/node_modules/@aws-sdk/shared-ini-file-loader/dist-cjs/slurpFile.js:5:27)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/application/node_modules/@aws-sdk/shared-ini-file-loader/dist-cjs/loadSharedConfigFiles.js:8:21)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
I am new to the AWS SDK so need some help registering my service to the service discovery. Thanks in advance!
@Ravi-Rsankar thanks for opening the issue, transferring it to the correct repo. https://github.com/aws/aws-sdk-js-v3
Same issue here when bumping @aws-sdk packages from 3.36.x to latest.... Do you have any updates. please?
Same here. Anyone found a solution?
Same issue here when bumping
@aws-sdkpackages from 3.36.x to latest.... Do you have any updates. please?
Update (May 23, 2022) - Bump to v3.95 across the board of all the services we are using brings no changes.
TypeError: Cannot destructure property 'readFile' of 'fs_1.promises' as it is undefined.
at Object.<anonymous> (../../node_modules/@aws-sdk/shared-ini-file-loader/dist-cjs/getSSOTokenFromFile.js:6:9)
at Object.<anonymous> (../../node_modules/@aws-sdk/shared-ini-file-loader/dist-cjs/index.js:7:22)

@ajredniwja My apologies for tagging you directly here. I'm desperately looking for any updates about the issue, since currently we are stuck at a really old version of AWS SDK and cannot upgrade because of the build failures.
Also, had anybody here found any workaround for that?
Facing the same issue with @aws-sdk/client-s3 on AWS CodeBuild with nodejs v14. Local builds with nodejs v14.15.x still working.
@mbunge Did you find a solution to this?
This is possibly related to https://github.com/aws/aws-sdk-js-v3/issues/3828
Any updates?
Hi guys, I'm using two AWS packages:
"@aws-sdk/client-secrets-manager": "^3.282.0"
"@aws-sdk/client-ssm": "^3.282.0"
Node.JS version 16.19.1 and I'm also facing this error, it's like:
TypeError: Cannot destructure property 'writeFile' of 'fs_1.promises' as it is undefined.
1 | const Confidence = require('confidence')
> 2 | const { SecretsManagerClient, GetSecretValueCommand } = require('@aws-sdk/client-secrets-manager')
I was testing a possible fix locally and I needed to change, from:
const fs_1 = require("fs");
const { writeFile } = fs_1.promises;
to (I saw it on that TODO):
const fs_1 = require("fs/promises");
const { writeFile } = fs_1;
In three files:
- writeSSOTokenToFile
- slurpFile
- getSSOTokenFromFile
After it I got success on the tests that I was running.
Can anyone help, applying those changes on the SDK?
I've just realized that I was mocking fs in my test:
jest.mock('fs')
I changed to use jest.spyOn(fs, 'writeFileSync').mockReturnValue({}), now it's working!
You can also mock the 'fs' module and retain functionality using jest.requireActual() like this:
const fs = require('fs');
jest.mock('fs', () => ({
...jest.requireActual('fs'),
openSync: jest.fn(),
createReadStream: jest.fn(),
writeFileSync: jest.fn(),
writeSync: jest.fn(),
closeSync: jest.fn()
}));
All 'fs' functionality will remain and only the listed functions will be mocked: openSync, createReadStream, writeFileSync, writeSync, closeSync.