如何使用.NET为CloudFront公开的Amazon S3生成签名URL [英] How to generate signed URLs for Amazon S3 exposed by CloudFront using.NET

查看:155
本文介绍了如何使用.NET为CloudFront公开的Amazon S3生成签名URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现的目的是生成一个指向CloudFront分布的singedURL,该分布源于S3存储桶。

The thing I want to achieve is to generate a singedURL pointing CloudFront distribution which originates from S3 bucket.

我设法对直接指向URL的URL进行了签名如以下AWS规范中所述的S3存储桶-使用AWS生成预签名对象URL用于.NET的SDK ,并且运行良好。

I have managed to sign the URL which points directly to the S3 bucket as described in following AWS spec - Generate a Presigned Object URL Using AWS SDK for .NET and it worked fine.

但是我真正需要的是生成签名的CloudFront URL。

But what I really need is to generate signed CloudFront URL.

我认为我的发行版已正确配置,因为我可以使用( https: //d298o8yem5c56d.cloudfront.net/123.pdf ),假设行为设置中的限制查看者访问权限:设置为
切换为后,如果没有signedURL,将无法再访问它。

I assume my Distribution is properly configured as I'm able to access it using (https://d298o8yem5c56d.cloudfront.net/123.pdf) assuming Restrict Viewer Access: is set to No in Behaviors settings. After switching it to Yes it can no longer be accessed without signedURL.

我试图使用AWS的示例代码开发人员指南:使用C#和.NET Framework创建URL签名

I was trying to use the sample code from AWS Developer Guide: Create a URL Signature Using C# and the .NET Framework

URL 生成了,但是我得到的是以下错误消息:

The URL was generated, but what I get is following error message:

< Error>
< Code> AccessDenied< / Code>
<消息>访问被拒绝< /消息>
< / Error>

任何想法我应该检查什么?

Any ideas what should I check ?

推荐答案

最后,我已经使用AWS开发人员指南中的示例代码解决了该问题:使用C#和.NET Framework创建URL签名

Finally I've solved the issue using the sample code from AWS Developer Guide: Create a URL Signature Using C# and the .NET Framework

该问题似乎与PrivateKey.xml

The issue seem to be related to the PrivateKey.xml

请记住用您的PrivateKey替换PrivateKey.xml(可以从AWS根账户设置生成/下载)。
下一步,必须将其从PEM转换为XML(.NET要求)

Remember to replace PrivateKey.xml with your PrivateKey (which can be generated / downloaded from AWS root account settings). As a next step it has to be converted from PEM to XML (required by .NET)

从PEM转换为XML的好方法是使用-在线转换器

Nice and easy way to convert from PEM to XML is by using an - online converter

这篇关于如何使用.NET为CloudFront公开的Amazon S3生成签名URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆