-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
227 additions
and
29 deletions.
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
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,54 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/sqs" | ||
) | ||
|
||
type sqsClient struct { | ||
svc *sqs.Client | ||
queueURL string | ||
} | ||
|
||
type CloudWatchEvent struct { | ||
Version string `json:"version"` | ||
ID string `json:"id"` | ||
DetailType string `json:"detail-type"` | ||
Source string `json:"source"` | ||
Account string `json:"account"` | ||
Time time.Time `json:"time"` | ||
Region string `json:"region"` | ||
Resources []string `json:"resources"` | ||
Detail json.RawMessage `json:"detail"` | ||
} | ||
|
||
func (c sqsClient) SendMessage(ctx context.Context, detailType string, detail json.RawMessage) error { | ||
v, err := json.Marshal(CloudWatchEvent{ | ||
Version: "0", | ||
ID: "63eb7e5f-1f10-4744-bba9-e16d327c3b98", | ||
DetailType: detailType, | ||
Source: "opg.poas.sirius", | ||
Account: "653761790766", | ||
Time: time.Now().UTC(), | ||
Region: "eu-west-1", | ||
Resources: []string{}, | ||
Detail: detail, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if _, err = c.svc.SendMessage(ctx, &sqs.SendMessageInput{ | ||
QueueUrl: aws.String(c.queueURL), | ||
MessageBody: aws.String(string(v)), | ||
}); err != nil { | ||
return fmt.Errorf("failed to send %s message: %w", detailType, err) | ||
} | ||
|
||
return 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
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