Skip to content

provides a mechanism for testing internet egress in an AWS VPC by creating a VPC Lambda via Cloudformation stack to which custom test URLs can be passed.

License

Notifications You must be signed in to change notification settings

GESkunkworks/fliptest

Repository files navigation

fliptest

Package fliptest provides a mechanism for testing internet egress in an AWS VPC by creating a VPC Lambda via Cloudformation stack to which custom test URLs can be passed.

Read the docs: https://godoc.org/github.com/GESkunkworks/fliptest

Sample usage:

package main

import (
    "fmt"
    "encoding/json"

    "github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
    
    "github.com/GESkunkworks/fliptest"
)

func main() {
    // setup session for flippage
    var sess *session.Session
    sess = session.Must(session.NewSessionWithOptions(session.Options{
        Config:  aws.Config{Region: aws.String("us-east-1")},
        Profile: "account1",
    }))

    input := fliptest.FlipTesterInput{
        Session:     sess,
        SubnetId:    "subnet-d3297188",
        VpcId:       "vpc-c8a6c3ae",
        RetainStack: true,
    }
    test, err := fliptest.New(&input)
    if err != nil {
        panic(err)
    }
    err = test.Test()
    if err != nil {
        fmt.Println(err)
        // if it was the tests failing that caused the error
        // we can see results from the test
        if body, err := json.MarshalIndent(test.TestResults, "", "    "); err == nil {
            fmt.Println(string(body))
        }
    } else {
        // see results of the tests that passed
        if body, err := json.MarshalIndent(test.TestResults, "", "    "); err == nil {
            fmt.Println(string(body))
        }
        // if desired a simple activity log can be retrieved
        fmt.Println(test.GetLog())
    }
}

sample output:

$ go run main.go
[
    {
        "Name": "gopkg.in",
        "ElapsedTimeS": 0.49933934211730957,
        "Message": "got response code from URL",
        "Success": true,
        "Url": "https://gopkg.in",
        "ResponseCode": 200
    },
    {
        "Name": "google",
        "ElapsedTimeS": 0.690319299697876,
        "Message": "got response code from URL",
        "Success": true,
        "Url": "https://www.google.com",
        "ResponseCode": 200
    },
    {
        "Name": "time",
        "ElapsedTimeS": 0.9288179874420166,
        "Message": "got response code from URL",
        "Success": true,
        "Url": "https://www.nist.gov",
        "ResponseCode": 200
    }
]
starting test
creating stack
loading template file
waiting on stack
waiting on stack
waiting on stack
waiting on stack
waiting on stack
waiting on stack
waiting on stack
calling lambda
tests passed
retaining stack
tests completed

If you want to run custom tests via the Lambda console you can create some test events in the browser. The structure for the test event is like so:

{
    "RequestType": "RunAll",
    "TestUrls": [
        {
            "Name": "test-google",
            "Url": "https://www.google.com/"
        }
    ]
}

About

provides a mechanism for testing internet egress in an AWS VPC by creating a VPC Lambda via Cloudformation stack to which custom test URLs can be passed.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages