Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使ASPNETCORE中缓存的AWS API网关终结点无效?_C#_.net_Caching_Asp.net Core_Aws Api Gateway - Fatal编程技术网

C# 如何使ASPNETCORE中缓存的AWS API网关终结点无效?

C# 如何使ASPNETCORE中缓存的AWS API网关终结点无效?,c#,.net,caching,asp.net-core,aws-api-gateway,C#,.net,Caching,Asp.net Core,Aws Api Gateway,[注:我已经找到了答案,但很难在网上找到任何东西,所以我将其添加到这里] 我需要使用ASPNETCORE使单个AWS API网关端点的缓存无效 医生说要发送一个签名的请求。你在.NET中是如何做到这一点的?我在回答我自己的问题,因为我在网上找不到太多的信息,而且花了一点时间才开始工作。希望它能帮助别人 我在这里添加了代码: CacheInvalizationRequestBuilder.cs 如何使用代码 要发出请求,请使用类似以下代码: var url = $"/myendpoint"; v

[注:我已经找到了答案,但很难在网上找到任何东西,所以我将其添加到这里]

我需要使用ASPNETCORE使单个AWS API网关端点的缓存无效


医生说要发送一个签名的请求。你在.NET中是如何做到这一点的?

我在回答我自己的问题,因为我在网上找不到太多的信息,而且花了一点时间才开始工作。希望它能帮助别人

我在这里添加了代码:

CacheInvalizationRequestBuilder.cs 如何使用代码 要发出请求,请使用类似以下代码:

var url = $"/myendpoint";

var model = GetCacheInvalidationRequestModel(url);

var request = CacheInvalidationRequestBuilder.Build(model);

try
{
  // Hit the endpoint
  using (var response = request.GetResponse())
  {
    // Not currently doing anything with the response
  }
}
catch(Exception ex)
{
  Logger.LogError(ex, "Problem invalidating cache for url: " + url);
}
GetCacheInvalizationRequestModel方法可能类似于我在模型属性中作为IOOptions传递的内容:

AWS信息 用于生成签名请求的AWS文件如下:

您的AWS用户需要附加策略,如下所示:


注意:如果您愿意,可以使用通配符。

我对签名请求很头疼,我在groovy中工作,发现了这个包,如果您有时间,可以创建一个nuget包:为了补充Lee Gunto的回答,请注意,在创建签名请求时,Api网关阶段,例如:dev,应该在相对路径部分,而不是在主机中。仅供参考,我没有足够的声誉发表评论,所以作为答案发布。
using System;
using System.Collections.Generic;
using System.Text;

namespace Aws
{
    public class CacheInvalidationRequestModel
    {
        public string Region { get; set; }

        public string Host { get; set; }

        public string AbsolutePath { get; set; }

        public string QueryString { get; set; }

        public string AccessKey { get; set; }

        public string SecretKey { get; set; }
    }
}
var url = $"/myendpoint";

var model = GetCacheInvalidationRequestModel(url);

var request = CacheInvalidationRequestBuilder.Build(model);

try
{
  // Hit the endpoint
  using (var response = request.GetResponse())
  {
    // Not currently doing anything with the response
  }
}
catch(Exception ex)
{
  Logger.LogError(ex, "Problem invalidating cache for url: " + url);
}
private CacheInvalidationRequestModel GetCacheInvalidationRequestModel(string absolutePath)
{
    return new CacheInvalidationRequestModel()
    {
        Region = Options.Region,
        Host = Options.Host,
        AccessKey = Options.InvalidatorKey,
        SecretKey = Options.InvalidatorSecret,
        AbsolutePath = absolutePath
    };
}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "execute-api:InvalidateCache"
      ],
      "Resource": [
        "arn:aws:execute-api:region:account-id:api-id/stage-name/GET/resource-path-specifier"
      ]
    }
  ]
}