Hi everyone,
I was thinking it might be better to ask this question here first, before opening an issue. Checking out the current gamma release there is a lot to like in the v3 SDK, however when trying it out I was left a bit disappointed by the proposed new API. It doesn't feel like an API designed for node... yet there is no description in the README
or the issues giving insight into the design.
I'm not sure if this is just my personal biases regarding API design talking though. Hence this long question here:
Why is the "modular" API designed as a pattern of const c = new Client()
and c.send(new Command())
? I would have anticipated an API more in line with patterns in other libraries like const result = await command(options, client())
, that way we could easily curry SDK-functions with project-specific configuration etc.
Please ignore my non-usage of new
this question is really not about "why classes".
The current API feels very much like it is wrapping a set of RPC endpoints... which is absolutely fine, but wouldn't it be preferable to more closely align with other projects in this space.
On a related note:
Maybe the SDK could ship with a babel plugin or macro to rewrite the "enhanced v2" syntax to the "modular" one? The v2 syntax in many ways feels like a rather cohesive OOP-API, making it much easier to teach to juniors or team members who are not as familiar with AWS. The v3 API already raised questions like "what's a command" when we presented the v3 SDK as something new in a knowledge session.
Hi, also awaiting for the v3 api. Meanwhile - how does the "assume role" functionality work in V3 API? Our current setup requires assuming a role from another account, and somehow v2 API was able to do it under the hood. When calling commands with the v3 API, I get "Profile <profile> requires a role to be assumed, but no role assumption callback was provided.".
How to define such a callback?
{credentials: fromIni({
roleAssumer: async (credentials, params) => {
// no idea why we have to implement this ourselves.
const sts = new STSClient({credentials});
const response = await sts.send(new AssumeRoleCommand(params));
return {
accessKeyId: response.Credentials.AccessKeyId,
secretAccessKey: response.Credentials.SecretAccessKey,
sessionToken: response.Credentials.SessionToken,
expiration: response.Credentials.Expiration,
};
}
}
getObject
with the following:downloadFile = async (src: String, dst: String) => {
this.params.Key = path.basename(src);
var outFile = fs.createWriteStream(dst);
try {
const data = await this.s3
.send(new GetObjectCommand(this.params))
.Contents.array.forEach((element) => {
outFile.write(element);
});
console.log("Success", data);
} catch (err) {
console.log("Error", err);
}
};
uploadFile
, which works fine. However, this my impl creates a dst
file, but its empty (zero size). Could anybody point to my mistake? Thanks in advance !
Alright... After looking at solution of @Mousaka, I came up with the working solution:
const data = await this.s3.send(new GetObjectCommand(this.params)).then((response) => {
const receiveObject = new Promise<Buffer>((resolve) => {
const forBuffer = new PassThrough();
response.Body?.pipe(forBuffer);
forBuffer.on("data", (chunk) => {
outFile.write(chunk);
});
forBuffer.on("finish", () => {
outFile.end();
});
});
});
console.log("Success", data);
} catch (err) {
console.log("Error", err);
}
};
Thanks for building and supporting the v3 API !
Hello! How to instantiate S3Client
in a browser with custom credentials? I'd like to use .env
to pass creds to my JS code. Here's what I'm doing now:
const cfg = {
accessKeyId: process.env.KEY,
secretAccessKey: process.env.SECRET,
endpoint: process.env.HOST,
s3ForcePathStyle: true,
signatureVersion: "v4",
};
const s3 = new S3Client(cfg);
This works in Node
, but fails in the browser with the following error: "vue.runtime.esm.js?5593:619 [Vue warn]: Error in created hook: "Error: Credential is missing"
How do I work around this? Thank you!
@aws-sdk/client-appsync
seems to be for manipulating AppSync itself, I just want to query the GraphQL API
import { Readable } from 'stream';
const readStream = (stream: Readable): Promise<string> => {
return new Promise((res, rej) => {
let data = '';
stream.on('data', function (chunk) { data += chunk; });
stream.on('end', function () { res(data); });
stream.on('error', rej);
});
}
const params = { Bucket, Key };
logger.debug('S3 getObject >', params);
const result = (await s3.getObject(params)).Body as any;
const stream = Readable.from(result);
return readStream(stream);
const response = await s3.getObject({ Bucket: BUCKET, Key: imageName } );
let file_stream = response.Body;
let content_buffer = Buffer.from([]);
if (file_stream instanceof Readable) {
for await (const chunk of file_stream) {
content_buffer = Buffer.concat([content_buffer,chunk]);
}
} else {
throw new Error('Unknown object stream type.');
}
I keep getting typescript compilation errors when attempting to use @aws-sdk/client-s3 any suggestions as to which version works?
After uninstalling all the @aws-sdk packages and reinstalling @aws-sdk/client-s3-node works but @aws-sdk/client-sqs no longer works and I am getting Typescript errors when attempting to use the ListQueuesCommand. ListQueuesCommand incorrectly implements interface 'Command...
const { marshall } = require("@aws-sdk/util-dynamodb");
$response
field I could use instead of writing a middleware
const { CognitoIdentityClient, CreateIdentityPoolCommand } = require("@aws-sdk/client-cognito-identity");
const client = new CognitoIdentityClient({ region: "us-east-1" });
const params = {
/** input parameters. Example? */
};
const command = new CreateIdentityPoolCommand(params);
client
.send(command)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
const { requestId, cfId, extendedRequestId } = error.$metadata;
console.log({ requestId, cfId, extendedRequestId });
})
.finally(() => {
// finally.
});