当我的桌子上都有“哈希”和“范围”键时,我的项目无法保存。如果我只有哈希值,它就可以工作。
我的表在我的serverless.template文件中定义
"TestTable" : {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"TableName" : "Test",
"AttributeDefinitions" : [
{"AttributeName" : "UserId", "AttributeType" : "S"},
{"AttributeName" : "Id", "AttributeType" : "N"}
],
"KeySchema" : [
{"AttributeName" : "UserId", "KeyType" : "HASH"},
{"AttributeName" : "Id", "KeyType" : "RANGE"}
],
"ProvisionedThroughput" : {
"ReadCapacityUnits" : 3,
"WriteCapacityUnits" : 3
}
}
}
我的功能如下:
public async Task<APIGatewayProxyResponse> CreateAsync(APIGatewayProxyRequest request, ILambdaContext context)
{
var test = new Test();
test.Id = 1;
test.UserId = "Test";
await DDBContext.SaveAsync<Test>(test);
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK,
Body = "foo",
Headers = new Dictionary<string, string> { { "Content-Type", "text/plain" } }
};
return response;
}