Documentation ¶
Overview ¶
AWS utility functions to wrap some functionality and provide mocking capabilities for unit testing. At time of writing this deals with S3, SES, SNS, SQS and
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 ¶
- Constants
- func GetS3(sess *session.Session) (s3iface.S3API, error)
- func GetSession() (*session.Session, error)
- func GetSessionWithRegion(region string) (*session.Session, error)
- func SESSendEmail(emailAddress string, charset string, textBody string, htmlBody string, ...)
- func SNSSendSms(phonenumber string, message string) error
- type Event
- type MockS3Client
- func (m *MockS3Client) CopyObject(input *s3.CopyObjectInput) (*s3.CopyObjectOutput, error)
- func (m *MockS3Client) DeleteObject(input *s3.DeleteObjectInput) (*s3.DeleteObjectOutput, error)
- func (m *MockS3Client) FinishTest() error
- func (m *MockS3Client) GetObject(input *s3.GetObjectInput) (*s3.GetObjectOutput, error)
- func (m *MockS3Client) ListObjectsV2(input *s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, error)
- func (m *MockS3Client) PutObject(input *s3.PutObjectInput) (*s3.PutObjectOutput, error)
- func (m *MockS3Client) SkipPutChecks(path []string)
- type MockSNS
- type MockSigner
- type RealSNS
- type RealSQS
- type RealURLSigner
- type Record
- type SNSInterface
- type SQSInterface
Examples ¶
Constants ¶
const ErrNoMoreInputsExpected = "No more inputs expected for "
const ErrNothingToReturn = "Nothing to return from "
const ErrReturningError = "Returning error from "
const ErrWrongInput = "Incorrect input in "
Variables ¶
This section is empty.
Functions ¶
func GetSessionWithRegion ¶
GetSessionWithRegion - Can specify am S3 region, returns an AWS session
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 ¶
SNSSendSms Send an SMS via SNS
Types ¶
type Event ¶
type Event struct {
Records []Record
}
func (*Event) UnmarshalJSON ¶
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 // Unexpected requests we got UnexpListObjectsV2Input []*s3.ListObjectsV2Input UnexpGetObjectInput []*s3.GetObjectInput UnexpPutObjectInput []*s3.PutObjectInput UnexpDeleteObjectInput []*s3.DeleteObjectInput UnexpCopyObjectInput []*s3.CopyObjectInput 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 MockSNS ¶
type MockSNS struct { ExpInput []sns.PublishInput QueuedOutput []sns.PublishOutput }
func (*MockSNS) Publish ¶
func (msns *MockSNS) Publish(input *sns.PublishInput) (*sns.PublishOutput, error)
type MockSigner ¶
type MockSigner struct {
Urls []string
}
type RealSNS ¶
func (RealSNS) Publish ¶
func (rsns RealSNS) Publish(input *sns.PublishInput) (*sns.PublishOutput, error)
type RealSQS ¶
func (RealSQS) SendMessage ¶
func (rsqs RealSQS) SendMessage(input *sqs.SendMessageInput) (*sqs.SendMessageOutput, error)
type RealURLSigner ¶
type RealURLSigner struct { }
RealURLSigner - The runtime URL signer (as opposed to the mock)
type SNSInterface ¶
type SNSInterface interface {
Publish(input *sns.PublishInput) (*sns.PublishOutput, error)
}
type SQSInterface ¶
type SQSInterface interface {
SendMessage(msg *sqs.SendMessageInput) (*sqs.SendMessageOutput, error)
}