iamsigned

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

IAM signed

Provides helpers to send IAM-signed requests to AWS AppSync and AWS API Gateway services

  • Generates a v4 sign using IAM credentials
  • Properly sends the request to the aws service
  • Checks for http status error code
  • Parses graphQL response and checks for graphql-formatted errors (Appsync only)

Example Usage (Appsync GraphQL)

package main

import (
	"log"

	"github.com/aherve/iamsigned"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
)

var endpoint = "https://xxx.appsync-api.eu-west-1.amazonaws.com/graphql"
var region = "eu-west-1"

var myMutation = `
{
	"Query": "mutation(...)",
	"Variables": {...},
}
`

func main() {
	sess, err := session.NewSession(&aws.Config{Region: aws.String(region)})
	if err != nil {
		log.Fatal(err)
	}

	resp, err := iamsigned.AppSync([]byte(myMutation), endpoint, region, sess.Config.Credentials)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("SUCCESS : %s", string(resp))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIGateway

func APIGateway(payload []byte, endpoint, region, method string, creds *credentials.Credentials) ([]byte, error)

APIGateway signs and sends a request to API Gateway

func APIGatewayWithContext

func APIGatewayWithContext(ctx context.Context, payload []byte, endpoint, region, method string, creds *credentials.Credentials) ([]byte, error)

APIGatewayWithContext does the same as APIGatewayDeliver, with a context.Context object

func AppSync

func AppSync(payload []byte, endpoint, region string, creds *credentials.Credentials) ([]byte, error)

AppSync signs and send a request to appsync. It also parse the response and looks for graphql errors

func AppSyncWithContext

func AppSyncWithContext(ctx context.Context, payload []byte, endpoint, region string, creds *credentials.Credentials) ([]byte, error)

AppSyncWithContext does the same as AppSyncDeliver, with a context.Context object

func ParseGraphQLResponse

func ParseGraphQLResponse(body io.ReadCloser) (json.RawMessage, error)

ParseGraphQLResponse attempts to read the response, and extract grpahql-formatted errors

Types

type AWSService

type AWSService string
const (
	AppSyncService    AWSService = "appsync"
	APIGatewayService AWSService = "execute-api"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL