awsutil

package
v0.0.0-...-9ea7be0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Example (GetEventype)
var e Event

s := `{
    "Records": [
        {
            "eventVersion": "2.1",
            "eventSource": "aws:s3",
            "awsRegion": "us-east-1",
            "eventTime": "2022-06-22T14:36:07.988Z",
            "eventName": "ObjectCreated:CompleteMultipartUpload",
            "userIdentity": {
                "principalId": "AWS:AIDA6AOWGDOHF37MOKWLS"
            },
            "requestParameters": {
                "sourceIPAddress": "81.151.138.139"
            },
            "responseElements": {
                "x-amz-request-id": "PN134P5DBY0KJG2G",
                "x-amz-id-2": "bNfJtmP9ASZO++y92UKMgOrnNb2nF2BxG5lpxBj7N+05Iwq7qn+xtitbnifKJR2zQNPUQVN5lyQTTyDEX0ib1Y3t+bs/P9bH"
            },
            "s3": {
                "s3SchemaVersion": "1.0",
                "configurationId": "MTY5MDg4MjMtNGVkZS00MjQyLTlhN2MtZDU0N2RiNTRmNzAx",
                "bucket": {
                    "name": "stagepipeline-rawdata202c7bd0-dmjs9376duys",
                    "ownerIdentity": {
                        "principalId": "AP902Y0PI20DF"
                    },
                    "arn": "arn:aws:s3:::stagepipeline-rawdata202c7bd0-dmjs9376duys"
                },
                "object": {
                    "key": "130089473-08-03-2022-19-24-00.zip",
                    "size": 41407836,
                    "eTag": "b34552c7ddea5f4fd266f0d1d9fa7116-5",
                    "sequencer": "0062B328C0F22C48E1"
                }
            }
        }
    ]
}`
t := e.getEventType([]byte(s))

fmt.Printf("%v\n", t)
Output:

1
Example (UnmarshalJSON)
var e Event

s := `{
    "Records": [
        {
            "eventVersion": "2.1",
            "eventSource": "aws:s3",
            "awsRegion": "us-east-1",
            "eventTime": "2022-06-22T14:36:07.988Z",
            "eventName": "ObjectCreated:CompleteMultipartUpload",
            "userIdentity": {
                "principalId": "AWS:AIDA6AOWGDOHF37MOKWLS"
            },
            "requestParameters": {
                "sourceIPAddress": "81.151.138.139"
            },
            "responseElements": {
                "x-amz-request-id": "PN134P5DBY0KJG2G",
                "x-amz-id-2": "bNfJtmP9ASZO++y92UKMgOrnNb2nF2BxG5lpxBj7N+05Iwq7qn+xtitbnifKJR2zQNPUQVN5lyQTTyDEX0ib1Y3t+bs/P9bH"
            },
            "s3": {
                "s3SchemaVersion": "1.0",
                "configurationId": "MTY5MDg4MjMtNGVkZS00MjQyLTlhN2MtZDU0N2RiNTRmNzAx",
                "bucket": {
                    "name": "stagepipeline-rawdata202c7bd0-dmjs9376duys",
                    "ownerIdentity": {
                        "principalId": "AP902Y0PI20DF"
                    },
                    "arn": "arn:aws:s3:::stagepipeline-rawdata202c7bd0-dmjs9376duys"
                },
                "object": {
                    "key": "130089473-08-03-2022-19-24-00.zip",
                    "size": 41407836,
                    "eTag": "b34552c7ddea5f4fd266f0d1d9fa7116-5",
                    "sequencer": "0062B328C0F22C48E1"
                }
            }
        }
    ]
}`
e.UnmarshalJSON([]byte(s))

fmt.Printf("%v\n", e.Records[0].EventSource)
Output:

aws:s3

Index

Examples

Constants

View Source
const ErrNoMoreInputsExpected = "No more inputs expected for "
View Source
const ErrNothingToReturn = "Nothing to return from "
View Source
const ErrReturningError = "Returning error from "
View Source
const ErrWrongInput = "Incorrect input in "

Variables

This section is empty.

Functions

func GetS3

func GetS3(sess *session.Session) (s3iface.S3API, error)

GetS3 - returns an S3 session

func GetSession

func GetSession() (*session.Session, error)

GetSession - returns an AWS session

func GetSessionWithRegion

func GetSessionWithRegion(region string) (*session.Session, error)

GetSessionWithRegion - Can specify am S3 region, returns an AWS session

func PurgeQueue

func PurgeQueue(sess session.Session, url string) error

func SESSendEmail

func SESSendEmail(emailAddress string, charset string, textBody string, htmlBody string, subject string, sender string, cc []string, bcc []string)

SESSendEmail - Send an email via SES

func SNSSendSms

func SNSSendSms(phonenumber string, message string) error

SNSSendSms Send an SMS via SNS

Types

type Event

type Event struct {
	Records []Record
}

func (*Event) UnmarshalJSON

func (event *Event) UnmarshalJSON(data []byte) error

UnmarshalJSON - Decode the JSON to the correct Event type

type MockS3Client

type MockS3Client struct {
	s3iface.S3API

	// Expected requests
	ExpListObjectsV2Input []s3.ListObjectsV2Input
	ExpGetObjectInput     []s3.GetObjectInput
	ExpPutObjectInput     []s3.PutObjectInput
	ExpDeleteObjectInput  []s3.DeleteObjectInput
	ExpCopyObjectInput    []s3.CopyObjectInput

	// Responses replayed as each request comes in
	QueuedListObjectsV2Output []*s3.ListObjectsV2Output
	QueuedGetObjectOutput     []*s3.GetObjectOutput
	QueuedPutObjectOutput     []*s3.PutObjectOutput
	QueuedDeleteObjectOutput  []*s3.DeleteObjectOutput
	QueuedCopyObjectOutput    []*s3.CopyObjectOutput

	AllowGetInAnyOrder    bool
	AllowDeleteInAnyOrder bool

	SkipPutCheckNames []string
	// contains filtered or unexported fields
}

MockS3Client - mock S3 client for unit tests. Don't forget to call FinishTest() at the end of your test to check that all calls to S3 were made, and there were no unexpected calls!

func (*MockS3Client) CopyObject

func (m *MockS3Client) CopyObject(input *s3.CopyObjectInput) (*s3.CopyObjectOutput, error)

func (*MockS3Client) DeleteObject

func (m *MockS3Client) DeleteObject(input *s3.DeleteObjectInput) (*s3.DeleteObjectOutput, error)

func (*MockS3Client) FinishTest

func (m *MockS3Client) FinishTest() error

NOTE: This function MUST be called at the end of a unit test/example test. Use defer when declaring MockS3Client!

func (*MockS3Client) GetObject

func (m *MockS3Client) GetObject(input *s3.GetObjectInput) (*s3.GetObjectOutput, error)

func (*MockS3Client) ListObjectsV2

func (m *MockS3Client) ListObjectsV2(input *s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, error)

func (*MockS3Client) PutObject

func (m *MockS3Client) PutObject(input *s3.PutObjectInput) (*s3.PutObjectOutput, error)

func (*MockS3Client) SkipPutChecks

func (m *MockS3Client) SkipPutChecks(path []string)

type MockSigner

type MockSigner struct {
	Urls []string
}

func (*MockSigner) GetSignedURL

func (m *MockSigner) GetSignedURL(s3iface.S3API, string, string, time.Duration) (string, error)

type RealURLSigner

type RealURLSigner struct {
}

RealURLSigner - The runtime URL signer (as opposed to the mock)

func (*RealURLSigner) GetSignedURL

func (r *RealURLSigner) GetSignedURL(svc s3iface.S3API, bucket string, path string, expirySec time.Duration) (string, error)

GetSignedURL - Generates a signed URL for a given S3 object

type Record

type Record struct {
	EventSource    string
	EventSourceArn string
	AWSRegion      string
	S3             events.S3Entity
	SQS            events.SQSMessage
	SNS            events.SNSEntity
}

Jump to

Keyboard shortcuts

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