我必须将文件从 API 端点传输到两个不同的存储桶。原始上传是使用:
curl -X PUT -F "data=@sample" "http://localhost:3000/upload/1/1"
Run Code Online (Sandbox Code Playgroud)
文件上传的端点:
curl -X PUT -F "data=@sample" "http://localhost:3000/upload/1/1"
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我使用两个PassThrough流,以便将请求流复制为两个可读流,如该 SO thread 中所建议的。
这段代码保持不变,这里有趣的是uploadToFirstS3和uploadToSecondS3函数。在这个最小的示例中,两者使用不同的配置执行完全相同的操作,我在这里仅使用一个。
什么效果好:
const PassThrough = require('stream').PassThrough;
async function uploadFile (req, res) {
try {
const firstS3Stream = new PassThrough();
const secondS3Stream = new PassThrough();
req.pipe(firstS3Stream);
req.pipe(secondS3Stream);
await Promise.all([
uploadToFirstS3(firstS3Stream),
uploadToSecondS3(secondS3Stream),
]);
return res.end();
} catch (err) {
console.log(err)
return res.status(500).send({ error: 'Unexpected error during file upload' });
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码(基于aws-sdk包)工作正常。我的问题是,我希望它与 …
我将改用新的 Node AWS SDK (v3),以利用其模块化和 Typescript 支持。我需要做的第一件事是编写 Lambda 函数,但我找不到支持处理函数签名的类型。中的类型@aws/client-lambda似乎都与管理Lambda 的客户端相关。
Node SDK 是否有用于在某处编写Lambda 的官方类型?尤其:
context?event论证,是否有可能来自其他 AWS 服务及其相应类型的事件列表?interface Event {
// This could be anything -- a custom structure or something
// created by another AWS service, so it makes sense that
// there isn't a discoverable type for this. There should be
// corresponding types for each service that can send events
// to Lambda functions though. Where …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Kinesis Shard 订阅事件。但是执行SubscribeToShardCommand挂起 5 分钟(订阅超时)然后抛出错误:
(node:2667) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at /home/mjpolak/Documents/company/project/node_modules/@aws-sdk/client-kinesis/protocols/Aws_json1_1.ts:4020:19
at processTicksAndRejections (internal/process/task_queues.js:88:5)
at Object.deserializeAws_json1_1SubscribeToShardCommand (/home/mjpolak/Documents/company/project/node_modules/@aws-sdk/client-kinesis/protocols/Aws_json1_1.ts:2583:21)
at /home/mjpolak/Documents/company/project/node_modules/@aws-sdk/middleware-serde/src/deserializerMiddleware.ts:20:18
at /home/mjpolak/Documents/company/project/node_modules/@aws-sdk/middleware-signing/src/middleware.ts:26:22
at StandardRetryStrategy.retry (/home/mjpolak/Documents/company/project/node_modules/@aws-sdk/middleware-retry/src/defaultStrategy.ts:125:38)
at /home/mjpolak/Documents/company/project/node_modules/@aws-sdk/middleware-logger/src/loggerMiddleware.ts:21:20
at /home/mjpolak/Documents/company/project/kinesis-subscribe.ts:85:29
Run Code Online (Sandbox Code Playgroud)
我正在寻找可以让我成功订阅的帮助。
完整代码:
const { StreamDescription } = await client.send(
new DescribeStreamCommand({
StreamName: 'streamName',
}),
);
const { StreamARN } = StreamDescription;
const { Consumers } = await client.send(
new ListStreamConsumersCommand({
StreamARN,
}),
);
let Consumer = Consumers.find((x) => x.ConsumerName == …Run Code Online (Sandbox Code Playgroud) 我刚刚升级到 AWS SDK V3,我不知道如何使用它配置 retryDelayOptions 和 customBackoff。我在AWS自己的API参考或网上找不到任何示例代码。这就是我之前所做的:
retryDelayOptions: { customBackoff: (retryCount) => 2 ** (retryCount * 100) },
maxRetries: 2
Run Code Online (Sandbox Code Playgroud)
我将上述内容作为选项传递给客户端构造函数。V3 的重试似乎发生了很大变化,如果没有任何示例,我无法理解 API。任何帮助深表感谢
问候,迪帕克
javascript amazon-web-services exponential-backoff retry-logic aws-sdk-js-v3
I'm using AWS SDK (v3) in my NodeJS/Typescript application, specifically their DynamoDBDocumentClient to easily marshall/unmarshall my entities to reduce the amount of code needed to query the database.
As my entities are complex objects, meaning that an instance holds, for example, another class-type, or a array of them; I couldn't find any tutorials online to explain what I'm missing (maybe I'm not and that is how things need to be done) as the document-client makes me marshall them …
node.js amazon-dynamodb typescript dynamodb-queries aws-sdk-js-v3
在旧版本的 javascript 中,我使用 ManagedUpload 函数将大文件上传到 s3,它将进行排队并管理文件的多部分。但在 V3 中,这个函数在文档中没有任何地方,是被删除了吗?或者还有其他选择吗?请帮忙...
使用 AWS 控制台 --> AWS Cost Management --> Cost Explorer 时 - 我得到以下值:
当我使用@aws-sdk/client-cost-explorer“EC2 - 其他”和“Amazon Load Balancer”时,我得到不同的结果。
配置:
import { CostExplorerClient, GetCostAndUsageCommand } from '@aws-sdk/client-cost-explorer';
const client = new CostExplorerClient({
region,
credentials: {
accessKeyId,
secretAccessKey
}
});
const params = {
TimePeriod: {
Start: startDate,
End: endDate
},
Filter: {
Dimensions: {
Key: 'SERVICE',
Values: [
'EC2 - Other', 'Amazon ElastiCache'
]
}
},
GroupBy: [
{
Type: 'DIMENSION',
Key: 'SERVICE',
},
],
Granularity: 'DAILY',
Metrics: [ …Run Code Online (Sandbox Code Playgroud) javascript amazon-web-services node.js aws-sdk-js aws-sdk-js-v3
我用来@aws-sdk/client-kms加密数据。我得到了 base64 字符串作为响应。现在我得到了Uint8Array。
const encryptedBlob = await kms.encrypt({
KeyId: kmsKey,
Plaintext: Buffer.from(JSON.stringify('data to encrypt')),
});
Run Code Online (Sandbox Code Playgroud)
加密的明文。当您使用 HTTP API 或 AWS CLI 时,该值是 Base64 编码的。否则,它不是 Base64 编码的。AWS文档中提到
有没有办法在nodeJs中获取base64作为响应。
我按照此说明在 Cognito 中实现自定义消息发送器https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-custom-sms-sender.html
所有这些都适用于类似的代码(我在 AWS Lambda 上使用 Typescript):
import {buildClient, CommitmentPolicy, KmsKeyringNode} from '@aws-crypto/client-node';
import b64 from 'base64-js';
const {decrypt} = buildClient(CommitmentPolicy.REQUIRE_ENCRYPT_ALLOW_DECRYPT);
const keyring = new KmsKeyringNode({keyIds: ["my-key-arn"]});
...
const {plaintext} = await decrypt(keyring, b64.toByteArray(event.request.code));
console.log(plainttext.toString()) // prints plain text exactly as I need
Run Code Online (Sandbox Code Playgroud)
然而,这个库@aws-crypto/client-node让我的包变得非常巨大,几乎有 20MB!可能是因为它依赖于一些较旧的 AWS 库......
我曾经使用模块化库,这样的库@aws-sdk/xxx确实提供了更小的包。
我发现对于加密/解密我可以使用@aws-sdk/client-kms. 但这不起作用!
我正在尝试以下代码:
import {KMSClient, DecryptCommand} from "@aws-sdk/client-kms";
import b64 from 'base64-js';
const client = new KMSClient;
await client.send(new DecryptCommand({CiphertextBlob: b64.toByteArray(event.request.code), KeyId: 'my-key-arn'}))
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误: …
aws-sdk-js ×6
node.js ×4
javascript ×3
amazon-kms ×2
typescript ×2
aws-lambda ×1
aws-sdk ×1
retry-logic ×1
stream ×1