Skip to content

aws4 ec2 access key and secret key sign http request

Notifications You must be signed in to change notification settings

DemoLiang/aws4-ec2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws4-ec2

aws4 ec2 access key and secret key sign http request

aws4 ec2签名校验

具体可以参考main函数示例

如果需要移除部分字段,只需要将对应的加密函数中的某些header字段移除即可,比如移除host字段:

	requestData := bytes.NewBufferString("")
	//移除HOST字段
	//r.Header.Set(headKeyHost, r.Host)

	requestData.Write([]byte(r.Method))
	requestData.Write(lf)

参考示例:

package main

import (
	"log"
	"net/http"

	aws4 "github.com/Demoliang/aws4-ec2/v4"
)

const (
	REGION  = "REGION-1"
	SERVICE = "SERVICE-1"
)

func main() {
	keys := aws4.Key{
		AccessKey: "access_key",
		SecretKey: "secret_key",
	}
	url := "http://127.0.0.1:8080/health"

	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		panic(err)
	}

	_, err = aws4.SignRequestWithAwsV4(req, &keys, REGION, SERVICE)
	if err != nil {
		log.Printf("sign request error:%v", err)
		return
	}

	_, _, err = aws4.CheckRequestWithAwsV4(req, &keys, REGION, SERVICE)
	if err != nil {
		log.Printf("check request error:%v", err)
		return
	}
	log.Printf("sign success and check success")
}

About

aws4 ec2 access key and secret key sign http request

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages