我正在代码中访问AWS SDK及其服务,如下所示:
var aws = require('aws-sdk');
const s3 = new aws.S3();
Run Code Online (Sandbox Code Playgroud)
我想看看初始化S3对象时要获取的凭证是什么。我尝试了以下方法,但显然无法从文档中找出如何正确使用方法和类的方法。
var credo = aws.config.Credentials().get();
var credo = aws.config.Credentials;
var credo = aws.config.credentials;
var credo = aws.Credentials().get();
var credo = aws.Credentials();
var credo = aws.Credentials;
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我获取此数据的正确方法吗?我觉得这部分的aws文档不容易理解。
编辑:我能够使用更新代码中的凭据 aws.config.update({accessKeyId: 'xxx', secretAccessKey: 'yyy', sessionToken:'zzz'
当我不像这样设置它们时,我想看看这些值是什么。未设置过程环境变量。我的凭证文件设置正确。
amazon-s3 amazon-web-services aws-cli aws-sdk aws-sdk-nodejs
在做一个教程时,我将数据批量加载到我的dynamoDB JobsApplication表中,大约有400个随机作业帖子.
使用Node.js和aws-sdk我执行扫描操作.
var AWS = require('aws-sdk');
AWS.config.update({
region: 'us-east-1'
});
var print = require('./../lib/helpers').printPretty;
var dynamodb = new AWS.DynamoDB();
var epochNow = 1506043477;
var params = {
"TableName": "GMJS.Job",
"FilterExpression": "CountryId = :country AND ClosingTime > :time",
"ExpressionAttributeValues": {
":country": {
"S": "18"
},
":time": {
"N": epochNow.toString()
}
},
"ReturnConsumedCapacity": "TOTAL"
};
dynamodb.scan(params).promise()
.then(print)
.catch(print);Run Code Online (Sandbox Code Playgroud)
我的表目前有5个RCU和WCU分配给它.扫描操作在不到2秒的时间内得出结果,除了结果显示此信息:
"Count": 7,
"ScannedCount": 100,
"ConsumedCapacity": {
"TableName": "GMJS.Job",
"CapacityUnits": 89.5
}
}
Size of data: 50.8 KB …Run Code Online (Sandbox Code Playgroud)I'm trying to build an application with a basic client-server infrastructure. The server infrastructure is hosted on AWS, and when a client logs on, it sends a message to the server to set up various infrastructure considerations. One of the pieces of infrastructure is an SQS Queue that the client can poll from to get updates from the server (eventually I'd like to build a push service but I don't know how for right now).
I'm building this application in …
在 aws node v2 sdk 中,我们可以在启动客户端后更新凭证
var AWS = require('aws-sdk');
var S3 = AWS.S3();
AWS.config.update({
accessKeyId: 'AccessKeyId',
secretAccessKey: 'SecretAccessKey',
sessionToken: 'SessionToken'
});
Run Code Online (Sandbox Code Playgroud)
我们可以在 v3 sdk 中启动客户端后更新凭据吗
var s3 = require('@aws-sdk/client-s3')
var s3Client = s3.S3Client();
// now update the credentials like in sdk v2
Run Code Online (Sandbox Code Playgroud) 根据文档,我应该在删除之前获取包含该项目的数据结构(如果没有错误)
我确实检查没有错误,但我得到了一个空对象data:
docClient.delete(params, (err, data) => {
if (err) {
console.error('Error tring to delete item:' + err);
callback(err, null); // error
} else if (!data.Items || data.Items.length == 0) {
console.info(JSON.stringify(data));
callback(null, null); // no items
} else {
console.info(JSON.stringify(data));
callback(null, data.Items[0].ExposeStartTimestamp);
}
});
Run Code Online (Sandbox Code Playgroud)
两者都打印空的 json: {}
我有几个用于管理不同项目的 AWS 配置文件。我们将默认的称为“user1”,将我想要使用的称为“user2”
因此,如果我只是这样做,aws s3 ls它当然会给我 user1 的信息,或者如果我这样做,aws s3 ls --profile=user2它会给我 user2 的信息,这里一切都很好
我也知道我可以export AWS_DEFAULT_PROFILE=user2这样做aws s3 ls,这正确地给了我 user2 的存储桶
问题是,我有一个 Node 应用程序,当我在本地运行时,我想使用 user2 的配置文件。我已经尝试过各种方式AWS_DEFAULT_PROFILE=user2 npm run dev,但不知道该怎么做?
问题如何运行本地 Node 程序并使其 AWS SDK 使用我所需的配置文件?
amazon-web-services aws-cli aws-sdk aws-sdk-nodejs aws-sdk-js
我正在使用@aws-crypto/client-nodenpm 模块使用KMS密钥加密解密文件。但是当我运行以下代码时。我收到错误“配置中缺少凭据”
const {
KmsKeyringNode,
encrypt,
decrypt
} = require("@aws-crypto/client-node");
const encryptData = async (plainText, context) => {
try {
const {
result
} = await encrypt(keyring, plainText, {
encryptionContext: context
});
return result;
} catch (e) {
console.log(e);
}
};
encryptData('hello world', {
stage: "test",
purpose: "poc",
origin: "us-east-1"
})
Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-web-services node.js amazon-kms aws-sdk-nodejs
我正在尝试在节点js中使用aws-sdk从redis获取数据。到目前为止,我可以使用 client-elasticache 连接缓存。
redisClient = new ElastiCacheClient({region : "REGION"});
Run Code Online (Sandbox Code Playgroud)
图书馆 :@aws-sdk/client-elasticache
但我无法找到任何直接方法来使用此客户端从缓存获取数据,例如我们在 io-redis 中的get()或mget() 。有没有办法使用 aws-sdk 获取这样的数据?
amazon-web-services amazon-elasticache aws-sdk aws-sdk-nodejs
我必须使用node.js从S3存储桶下载多个文件。为此,我必须编写for loop&调用s3.getObject(param)下载方法。下载文件后,我必须合并其内容。
我这样写:
var fileContentList = new ArrayList();
for(i=0; i<fileNameList.length i++){
s3.getObject({ Bucket: "my-bucket", Key: fileNameList.get(i) }, function (error, data) {
if (error != null) {
alert("Failed to retrieve an object: " + error);
} else {
alert("Loaded " + data.ContentLength + " bytes");
fileContentList.add(data.Body.toString());
}
}
);
}
//Do merging with the fileContentList.
Run Code Online (Sandbox Code Playgroud)
但是作为s3.getObject异步调用,当前线程继续前进,fileContentList而在执行合并时没有任何添加。
我该如何解决这个问题?任何的想法?
在aws-sdk中是否有任何同步方法来下载文件?
javascript amazon-s3 amazon-web-services node.js aws-sdk-nodejs
node.js ×5
aws-sdk ×4
amazon-s3 ×3
aws-cli ×2
aws-sdk-js ×2
amazon-kms ×1
amazon-sqs ×1
javascript ×1