跳转至

aws-auth: Lua resty 模块用于计算 AWS 签名 v4 授权头

安装

如果您尚未设置 RPM 仓库订阅,请 注册。然后您可以继续以下步骤。

CentOS/RHEL 7 或 Amazon Linux 2

yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install lua-resty-aws-auth

CentOS/RHEL 8+、Fedora Linux、Amazon Linux 2023

dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install lua5.1-resty-aws-auth

要在 NGINX 中使用此 Lua 库,请确保已安装 nginx-module-lua

本文档描述了 lua-resty-aws-auth v0.12,发布于 2017 年 1 月 13 日。


简单的 lua resty 工具,用于生成 Amazon v4 授权和签名头。

使用

local aws_auth = require "resty.aws-auth"
local config = {
  aws_host       = "email.us-east-1.amazonaws.com",
  aws_key        = "AKIDEXAMPLE",
  aws_secret     = "xxxsecret",
  aws_region     = "us-east-1",
  aws_service    = "ses",
  content_type   = "application/x-www-form-urlencoded",
  request_method = "POST",
  request_path   = "/",
  request_body   = { hello="world" } -- 所有请求参数的表
}

local aws = aws_auth:new(config)

-- 获取生成的授权头
-- 例如: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/iam/aws4_request,
---    SignedHeaders=content-type;host;x-amz-date, Signature=xxx
local auth = aws:get_authorization_header()

-- 获取 x-amz-date 头
local amz_date = aws:get_amz_date_header()

Authorizationx-amz-date 头添加到 ngx.req.headers

aws:set_ngx_auth_headers()

参考 使用签名 V4 签署 AWS AWS 服务命名空间列表 AWS 区域和端点

GitHub

您可以在 nginx-module-aws-auth 的 GitHub 仓库 中找到此模块的其他配置提示和文档。