更改日志说
Load config from ~/.aws/config if AWS_SDK_LOAD_CONFIG is set.
找不到有关如何加载配置的任何示例或文档。任何帮助!
我的 dynamo db 中有两个表,一个是候选表,另一个是用户表我想在 dynamo db 中使用 batchWriteItem 以便在表中添加数据。
我格式化的查询如下
var user = {
userid: usrid,
role: 'candidate',
password: vucrypt.encryptpass(pass)
};
var canduser = {
fname: req.body.fname,
lname: req.body.lname,
location: req.body.location,
phone: req.body.phone,
ccode: req.body.ccode,
grad: req.body.grad,
pgrad: req.body.pgrad,
ograd: req.body.ograd,
experience: exp,
linkedin: req.body.linkedin,
terms: tandc
};
canduser = vutools.fixcanduser(canduser);
canduser.userid = usrid;
var writes = {
'users': [{put: user}],
'candidate': [{put: canduser}],
};
Run Code Online (Sandbox Code Playgroud)
但如果我使用
dynamodb.batchWriteItem(writes, function(err, regdata) {
}
它以错误告终。如何编写正确的查询?我得到的错误是这个。
MultipleValidationErrors: There were 3 validation errors:
* MissingRequiredParameter: …Run Code Online (Sandbox Code Playgroud) 我必须实现一个 NodeJS 应用程序,让用户在运行时选择要查询的几个 AWS 配置文件中的哪一个(prod、beta 或 dev)。是否可以通过以编程方式传入单独的凭证集来查询同一进程中的多个 AWS 实例?或者 SDK 是否只允许单个进程连接到一个配置文件?
DynamoDB 的Number类型支持 38 位十进制精度。这不足以存储需要 39 位数字的 128 位整数。最大值为 340,282,366,920,938,463,463,374,607,431,768,211,455 为 unsigned 128 位整数或 170,141,183,460,469,231,731,861,730,861,730,861,730,861,861,861,873 这些都是 39 位数字。
如果我不能存储128位,那么有多少整型数据位可我在商店Number?
我在路由器后面使用 AWS SDK SQS(带有 Nodejs),为了通过路由器,我需要在请求中包含一个自定义标头。
我看过这个文档(https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Request.html#build-event),它讨论了REQUEST 中的.on ('build')事件:
var req = s3.putObject(params);
req.on('build', function() {
req.httpRequest.headers['Custom-Header'] = 'value';
});
req.send(function(err, data) { ... });
Run Code Online (Sandbox Code Playgroud)
但是,使用SQS 服务不起作用,没有抛出任何错误并且自定义标头未包含在 REQUEST 中。
是否可以使用 AWS SDK 包含自定义标头 SQS 服务的?如何使这项工作?
我能够在 NodeJS 中本地从 AWS SSM 参数存储中检索数据,但当我将代码移至 Lambda 时却无法检索数据。
我搜索过,但没有找到很多使用 NodeJS 设置 Lambda 且不使用“无服务器”框架的示例。
我知道我错过了一些简单的事情。我只是还不知道什么。
我已向 lambda 的 IAM 策略授予以下权限:
"Effect": "Allow",
"Action": [
"ssm:PutParameter",
"ssm:GetParameter"
],
"Resource": [
"arn:aws:ssm:region:account-id:parameter/Name/Of/Parameter"
]
Run Code Online (Sandbox Code Playgroud)
AWS.config.update({region: 'my-region'})
const ssm = new AWS.SSM()
ssm.getParameter({
Name: '/Name/Of/Parameter',
WithDecryption: false
}, (err, data) => {
if (err) {
reject(err);
}
if (data.Parameter !== undefined) {
resolve(data.Parameter.Value);
}
reject(new Error('No Parameter'));
});
Run Code Online (Sandbox Code Playgroud)
本地数据被定义。在我的 lambda 中,我收到错误:“{ TypeError: Cannot read property 'Parameter' of null” 意思是 'data' 为空,这是错误的。
任何见解都值得赞赏。
我有一个奇怪的问题,我似乎无法去任何地方。我已经遵循了网上的所有内容(多个教程等),但无法让sts.assumeRole工作。
我的设置:
我有一个在子 AWS 账户 1中运行的机器人,我需要来自主 AWS 账户的定价信息。
因此,我在主 AWS 账户上创建了一个角色来拥有 AWS ce:* 访问权限,如下所示:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["ce:*"],
"Resource": ["*"]
}]
}
Run Code Online (Sandbox Code Playgroud)
信任关系
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com",
"AWS": "arn:aws:iam::SubAWSaccount1-ID:role/instance-profile"
},
"Action": "sts:AssumeRole"
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在,这是附加到在子 AWS 账户 1上运行的 EC2 实例的实例配置文件:
"Version": "2012-10-17", …Run Code Online (Sandbox Code Playgroud) 我需要执行这样的查询: select * from table where抽样日期如“2020-05-%”
为此,我呼吁
db.query({
TableName: "Tubes",
Select: "ALL_ATTRIBUTES",
IndexName: "sampling_date_idx",
KeyConditionExpression: " sampling_date > :sampling_date ",
ExpressionAttributeValues:{ ':sampling_date': {'S': '2020-05-'}}
}, function(error: AWSError, data: QueryOutput){
console.log(error, data);
})
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
{"errorType":"Error","errorMessage":"{\"message\":\"Query key condition not supported\",\"code\":\"ValidationException\",
Run Code Online (Sandbox Code Playgroud)
我的桌子:
this.tubes = new dynamodb.Table(this, "tubes", {
tableName: "Tubes",
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
partitionKey: {
name: "id",
type: dynamodb.AttributeType.STRING
},
pointInTimeRecovery: true,
removalPolicy: cdk.RemovalPolicy.RETAIN
});
this.tubes.addGlobalSecondaryIndex({
indexName: "sampling_date_idx",
sortKey: {
name: 'sampling_date_srt',
type: AttributeType.STRING
},
partitionKey: {
name: "sampling_date",
type: AttributeType.STRING,
},
})
Run Code Online (Sandbox Code Playgroud) 我们正在使用createReadStream()aws-sdk从节点中的S3 流式传输内容。我们想添加 etag 支持。如果我们从客户端添加“If-None-Match”标头,s3 会抛出 NotModified 作为我似乎无法处理的错误。
retrieveFile = function(req, res) {
var s3 = new AWS.S3();
var params = {
Bucket: bucket,
key: key
};
if (req.get('If-None-Match')) {
params.IfNoneMatch = req.get('If-None-Match');
}
return s3.getObject(params).on('httpHeaders', function(statusCode, headers) {
if (headers.etag) {
res.set('etag', headers.etag);
}
if (headers['content-length']) {
return res.set('content-length', headers['content-length']);
}
}).createReadStream().pipe(res);
};
Run Code Online (Sandbox Code Playgroud)
我试过监听流上的事件并对从 getObject 返回的请求使用回调。我可以通过这种方式获取错误消息,但是 aws-sdk 中的其他内容似乎正在终止我的进程。
/Projects/my-app/node_modules/aws-sdk/lib/request.js:31
throw err;
^
NotModified: null
at Request.extractError (/Projects/my-app/node_modules/aws-sdk/lib/services/s3.js:519:35)
at Request.callListeners (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at Request.emit (/Projects/my-app/node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (/Projects/my-app/node_modules/aws-sdk/lib/request.js:673:14)
at Request.transition …Run Code Online (Sandbox Code Playgroud) amazon-s3 amazon-web-services node.js aws-sdk aws-sdk-nodejs
我正在尝试从我的 DynamoDB 数据库中获取一个项目。我的代码目前的编写方式,我无法从 DynamoDB 检索任何数据。我一定是做错了什么,因为据我从测试中可以看出,我的回调没有被调用。
昨天我花了一整天的时间,自从我今天早上醒来以来一直在修补它,但没有成功。
如果有人能深入了解我在这里做错了什么,我将不胜感激。提前感谢大家!
最后说明:Lambda 函数本身的超时设置为 5 分钟。所以我不认为 Lambda 函数在 db 查询可以返回之前超时。当我运行该函数时,它会在片刻后退出。
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB();
var response = null;
var test = false;
function getFromDB(callback) {
const params = {
TableName: process.env['DB_TABLE_NAME'] // evaluates to 'test-table',
Key: {
"id": {
S: postId // evaluates to a big string, pulling it in from an SNS message. Verified it with console.log(). It stores the expected value.
}
}
};
dynamodb.getItem(params, function(err, data) { …Run Code Online (Sandbox Code Playgroud) aws-sdk-nodejs ×10
aws-sdk ×5
node.js ×4
aws-lambda ×2
javascript ×2
amazon-s3 ×1
amazon-sqs ×1
assume-role ×1
aws-sdk-js ×1
aws-ssm ×1