Golangで署名付きURLを発行します。
import sign "github.com/aws/aws-sdk-go/service/cloudfront/sign"
func main() {
type CFConfig struct {
KeyID string
Domain string
KeyPath string
}
// cloud front config
cfConf := &model.CFConfig{
KeyID: "xxxxxxxxxxxxCQ"
Domain: "http://xxx.cloudfront.net",
KeyPath: "key/xxxxxxxxxxxxCQ",
}
privKey, err := sign.LoadPEMPrivKeyFile(r.cfConf.KeyPath)
if err != nil {
log.Println("failed to load pem file:", err)
return "", err
}
keyID := r.cfConf.KeyID
signer := sign.NewURLSigner(keyID, privKey)
path := "s3アクセスを許可したいコンテンツのパス"
signedURL, err := signer.Sign(r.cfConf.Domain+path, time.Now().Add(1*time.Hour))
if err != nil {
log.Fatalf("Failed to sign url, err: %s\n", err.Error())
}
return signedURL, err
}