AWS CF Signer - 简化 CloudFront 和 Signed Cookies 的签名过程

AWSCFSigner是一个Python库,帮助开发者自动创建CloudFront签名URL和定制SignedCookies,支持多种算法,提高效率并保证安全性。通过简单API和示例展示其使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

AWS CF Signer - 简化 CloudFront 和 Signed Cookies 的签名过程

aws_cf_signer Ruby gem for signing AWS Cloudfront URLs for serving private content 项目地址: https://gitcode.com/gh_mirrors/aw/aws_cf_signer

AWS CF Signer 是一个简单的 Python 库,可以帮助您轻松地为 Amazon CloudFront 分发和自定义-signed cookies 创建签名。它消除了手动创建所需哈希和日期的过程,为您提供了一个易于使用的接口。

项目简介

AWS CF Signer 可以让您:

  • 自动为 CloudFront 分发创建签名 URL。
  • 使用自定义策略生成 Signed Cookies。
  • 支持多种算法(包括 HMAC-SHA1、HMAC-SHA256 和 RSA)。

使用此库可以节省时间,减少出错的可能性,并简化与 Amazon CloudFront 相关的签名过程。

如何使用

首先,安装 AWS CF Signer:

pip install aws-cf-signer

接下来,您可以导入并使用 aws_cf_signer 模块来创建签名 URL 或 signed cookies。

创建签名 URL

以下示例展示了如何使用 AWS CF Signer 为特定分布和路径创建签名 URL:

import json
from datetime import timedelta
from aws_cf_signer import generate_presigned_url

access_key = 'YOUR_ACCESS_KEY'
secret_key = 'YOUR_SECRET_KEY'

distribution_id = 'YOUR_DISTRIBUTION_ID'
url_path = '/path/to/your/resource'

 expiration = (datetime.utcnow() + timedelta(hours=1)).isoformat()

 policy_document = json.dumps({
    "Statement": [
        {
            "Resource": f"https://{distribution_id}.cloudfront.net{url_path}",
            "Condition": {
                "DateLessThan": {"AWS:EpochTime": expiration}
            }
        }
    ]
 })

signed_url = generate_presigned_url(
    access_key, secret_key,
    distribution_id, url_path, policy_document=policy_document,
    algorithm='HMAC-SHA256')

print(signed_url)

生成Signed Cookies

以下示例演示了如何使用 AWS CF Signer 为特定分布和策略创建 signed cookie:

import json
from aws_cf_signer import generate_signed_cookies

access_key = 'YOUR_ACCESS_KEY'
secret_key = 'YOUR_SECRET_KEY'

distribution_id = 'YOUR_DISTRIBUTION_ID'
cookie_expiration = (datetime.utcnow() + timedelta(hours=1)).isoformat()
policy_document = json.dumps({
    "Statement": [
        {
            "Resource": f"https://{distribution_id}.cloudfront.net/*",
            "Condition": {
                "DateLessThan": {"AWS:EpochTime": cookie_expiration}
            }
        }
    ]
})

cookies = generate_signed_cookies(access_key, secret_key, distribution_id,
                                   policy_document=policy_document,
                                   algorithm='HMAC-SHA256')

print(cookies)

特点

AWS CF Signer 具有以下特点:

  • 易于使用:提供简洁的 API,便于集成到现有代码中。
  • 多种算法支持:支持 HMAC-SHA1、HMAC-SHA256 和 RSA 加密算法。
  • 安全性:确保通过安全的方法处理敏感数据,如访问密钥和秘密密钥。

尝试 AWS CF Signer!

如果您正在寻找一种简化 Amazon CloudFront 分发和 signed cookies 签名过程的方法,AWS CF Signer 是一个不错的选择。要开始使用,请访问以下链接:

<>

让我们知道您对 AWS CF Signer 的看法!欢迎在项目的 GitHub 页面上提交反馈或问题。

再次强调,如果感兴趣的话,请尝试 <https://gitcode

aws_cf_signer Ruby gem for signing AWS Cloudfront URLs for serving private content 项目地址: https://gitcode.com/gh_mirrors/aw/aws_cf_signer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

纪亚钧

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值