我创建了一个模型,当我在本地机器上运行我的后端函数时它正在工作,但是当它使用 AWS 时,我在查询表时遇到了身份验证问题:
2022-02-18T08:54:58.149Z 31785a81-ea8c-434b-832f-6dcff583c01c ERROR Unhandled Promise Rejection
{
"errorType": "Runtime.UnhandledPromiseRejection",
"errorMessage": "AccessDeniedException: User: arn:aws:sts::xxxxxxxxx:assumed-role/dev-production-history-role/ppc-backend-functions-dev-queryProductionHistoryItems is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:eu-west-1:xxxxxxxxxxxx:table/dev-production-history-table",
"trace": [
"Runtime.UnhandledPromiseRejection: AccessDeniedException: User: arn:aws:sts::xxxxxxxxx:assumed-role/dev-production-history-role/ppc-backend-functions-dev-queryProductionHistoryItems is not authorized to perform: dynamodb:CreateTable on resource: arn:aws:dynamodb:eu-west-1:xxxxxxxxx:table/dev-production-history-table",
" at process.<anonymous> (/var/runtime/index.js:35:15)",
" at process.emit (events.js:400:28)",
" at processPromiseRejections (internal/process/promises.js:245:33)",
" at processTicksAndRejections (internal/process/task_queues.js:96:32)"
]
}
这就是我的模型的定义方式:
const model = dynamoose.model<ProductionHistory>(DatabaseTableNames.productionHistoryTable, {schema});
从查看可能的解决方案来看,似乎添加{“create”: false}
参数可能会解决问题,但在 Dynamoose 版本 3 中,您无法添加三个参数,因此这不起作用:
const model = dynamoose.model<ProductionHistory>(DatabaseTableNames.productionHistoryTable,
schema, {“create”: false});
有谁知道如何克服这个问题,以便它适用于 Dynamoose 版本 3?
我已经按照 Charlie Fish 的建议进行了更改,现在出现以下错误:
2022-02-18T16:39:39.211Z b00a36b8-c612-4886-b9fc-da7084527bf0 INFO AccessDeniedException: User: arn:aws:sts::874124979428:assumed-role/dev-production-history-role/ppc-backend-functions-dev-queryProductionHistoryItems is not authorized to perform: dynamodb:Query on resource: arn:aws:dynamodb:eu-west-1:874124979428:table/dev-production-history-table
at deserializeAws_json1_0QueryCommandError (/var/task/node_modules/dynamoose/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:2984:41)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async /var/task/node_modules/dynamoose/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
at async /var/task/node_modules/dynamoose/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:11:20
at async StandardRetryStrategy.retry (/var/task/node_modules/dynamoose/node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46)
at async /var/task/node_modules/dynamoose/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22
at async main (/var/task/node_modules/dynamoose/dist/aws/ddb/internal.js:6:20)
at async /var/task/node_modules/dynamoose/dist/ItemRetriever.js:105:32
at async Object.queryByDate (/var/task/functions/production-history/query.js:1:1723)
at async Runtime.l [as handler] (/var/task/functions/production-history/query.js:1:1974) {
__type: 'com.amazon.coral.service#AccessDeniedException',
'$fault': 'client',
'$metadata': {
httpStatusCode: 400,
requestId: 'DCB6SNOH9O2NTRAS9LL3OJGEU7VV4KQNSO5AEMVJF66Q9ASUAAJG',
extendedRequestId: undefined,
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
},
'$response': HttpResponse {
statusCode: 400,
headers: {
server: 'Server',
date: 'Fri, 18 Feb 2022 16:39:39 GMT',
'content-type': 'application/x-amz-json-1.0',
'content-length': '331',
connection: 'keep-alive',
'x-amzn-requestid': 'DCB6SNOH9O2NTRAS9LL3OJGEU7VV4KQNSO5AEMVJF66Q9ASUAAJG',
'x-amz-crc32': '2950006190'
},
body: IncomingMessage {
_readableState: [ReadableState],
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
socket: null,
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Array],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 400,
statusMessage: 'Bad Request',
client: [TLSSocket],
_consuming: false,
_dumped: false,
req: [ClientRequest],
[Symbol(kCapture)]: false,
[Symbol(RequestTimeout)]: undefined
}
}
}
这是我现在的代码:
const model = dynamoose.model<ProductionHistory>(DatabaseTableNames.productionHistoryTable, schema);
const Table = new dynamoose.Table(DatabaseTableNames.productionHistoryTable, [model], {"create": false, "waitForActive": false});
有任何想法吗?