【发布时间】:2020-07-27 04:11:26
【问题描述】:
我正在使用 DynamoDb 设置一个可以通过 API 调用更新的表。在浏览了DynamoDB文档之后,我在.NET中写了一个更新项功能如下:
public static async Task IntAsync(string phone, string s)
{
getAsync(phone).Wait();
AmazonDynamoDBConfig clientConfig = new AmazonDynamoDBConfig();
clientConfig.RegionEndpoint = RegionEndpoint.APSouth1;
try
{
using (IAmazonDynamoDB ddbClient = new AmazonDynamoDBClient(clientConfig))
{
await ddbClient.UpdateItemAsync(new UpdateItemRequest
{
TableName = "TableName",
Key = new Dictionary<string, AttributeValue>
{
{"ID", new AttributeValue{S=phone} },
},
ExpressionAttributeNames = new Dictionary<string, string>()
{
{"#P", "Progress" },
{"#A", "attempt"+count.ToString() },
{"#S", s }
},
ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
{
{":s",new AttributeValue {S=DateTime.Now.ToString()}},
},
UpdateExpression = "SET #P.#A.#S = :s",
ConditionExpression = "attribute_not_exists(#P.#A.#S)"
});
}
}
catch (Exception e)
{
Console.WriteLine("Update Error: " + e.Message);
}
}
问题: 此函数在通过 main 调用时工作正常,并且更改会立即反映,但是通过 .Net core Get api 请求调用相同的函数不会返回任何结果并继续在邮递员上发送请求。
获取请求如下:
public async Task<string> GetAsync(string mobile, string s)
{
await Program.IntAsync(string mobile, string s);
return "Done";
}
但是,从 get 请求中删除函数调用会导致请求通过,并且所有其他函数都可以正常工作。我还有其他几个通过 get 请求执行的更新请求,它们都运行良好。
【问题讨论】:
标签: c# .net-core amazon-dynamodb