Categorygithub.com/fsaravia/awsign
modulepackage
0.0.1
Repository: https://github.com/fsaravia/awsign.git
Documentation: pkg.go.dev

# README

Golang awsign

Build Status Go Report Card

awsign is a Go library for signing AWS requests according to the specifications of the AWS Signature Version 4 Signing Process.

Why?

AWS provides a full featured Go SDK but this tiny library allows to sign just simple requests when you don't need to install the full SDK. Besides, Go is fun :wink:

Install

$ go get github.com/fsaravia/awsign

Usage

Create the HTTP request you'd like to sign.

parsedUrl, _ := url.Parse("https://iam.amazonaws.com/")

query := url.Values{}
query.Add("Action", "ListUsers")
query.Add("Version", "2010-05-08")

parsedUrl.RawQuery = query.Encode()

request, _ := http.NewRequest(http.MethodGet, parsedUrl.String(), nil)

request.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")

Instantiate a Signer and sign it!

signer := awsign.Signer{
	Region:          "us-east-1",
	Service:         "iam",
	AccessKeyID:     "<YOUR-ACCESS-KEY-ID>",
	AccessKeySecret: "<YOUR-ACCESS-KEY-SECRET>"}

signer.Sign(request, "")

If your request includes a body, pass its payload in the second parameter of Sign

// Payload to send an email via SES

form := url.Values{}
form.Add("Action", "SendEmail")
form.Add("Destination.ToAddresses.member.1", "[email protected]")
form.Add("Message.Body.Text.Data", "Test email body")
form.Add("Message.Subject.Data", "Test email subject")
form.Add("Source", "[email protected]")

payload := form.Encode()

request, _ := http.NewRequest(requestMethod, parsedUrl.String(), strings.NewReader(payload))

signer := awsign.Signer{
	Region:          "us-east-1",
	Service:         "ses",
	AccessKeyID:     "<YOUR-ACCESS-KEY-ID>",
	AccessKeySecret: "<YOUR-ACCESS-KEY-SECRET>"}

signer.Sign(request, payload)

# Functions

Signature generates the request signature that has to be added to the Authorization header of a requests according to AWS documentation.

# Structs

Signer is a convenience mechanism for storing the configuration variables that are necessary for signing requests made to AWS, it allows users to instantiate it once and reuse it over several requests.