-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for publishing to an AWS SQS
- Loading branch information
Showing
7 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/vendor | ||
/dist | ||
/private |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
) | ||
|
||
const ( | ||
// Region is the default aws region | ||
Region = "us-east-2" | ||
// MaxRetries is the number of retries when connecting to aws | ||
MaxRetries = 5 | ||
) | ||
|
||
// Session is a global session handle | ||
var Session *session.Session | ||
|
||
// NewSession creates a new aws session | ||
func NewSession(accessKeyID, secretAccessKey string) *session.Session { | ||
return session.New(&aws.Config{ | ||
Region: aws.String(Region), | ||
Credentials: credentials.NewStaticCredentials(accessKeyID, secretAccessKey, ""), | ||
MaxRetries: aws.Int(MaxRetries), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package aws | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/sqs" | ||
) | ||
|
||
const ( | ||
// QueueURL is the URL of the message queue | ||
queueURL = "https://sqs.us-east-2.amazonaws.com/082866812839/ooni-collector.fifo" | ||
) | ||
|
||
// SendMessage sends a message to the AWS SQS queue | ||
func SendMessage(sess *session.Session, body string, groupID string) (*string, error) { | ||
if sess == nil { | ||
return nil, errors.New("invalid aws Session") | ||
} | ||
|
||
svc := sqs.New(sess) | ||
sendParams := &sqs.SendMessageInput{ | ||
MessageBody: aws.String(body), | ||
QueueUrl: aws.String(queueURL), | ||
MessageGroupId: aws.String(groupID), | ||
} | ||
sendResp, err := svc.SendMessage(sendParams) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return sendResp.MessageId, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters