@@ -25,11 +25,12 @@ var (
25
25
)
26
26
27
27
var (
28
- sourceQueue = kingpin .Flag ("source" , "Source queue name to move messages from." ).Short ('s' ).Required ().String ()
29
- destinationQueue = kingpin .Flag ("destination" , "Destination queue name to move messages to." ).Short ('d' ).Required ().String ()
30
- region = kingpin .Flag ("region" , "AWS region for source and destination queues." ).Short ('r' ).Default ("us-west-2" ).String ()
31
- profile = kingpin .Flag ("profile" , "Use a specific profile from AWS credentials file." ).Short ('p' ).Default ("" ).String ()
32
- limit = kingpin .Flag ("limit" , "Limits number of messages moved. No limit is set by default." ).Short ('l' ).Default ("0" ).Int ()
28
+ sourceQueue = kingpin .Flag ("source" , "The source queue name to move messages from." ).Short ('s' ).Required ().String ()
29
+ destinationQueue = kingpin .Flag ("destination" , "The destination queue name to move messages to." ).Short ('d' ).Required ().String ()
30
+ region = kingpin .Flag ("region" , "The AWS region for source and destination queues." ).Short ('r' ).Default ("" ).String ()
31
+ profile = kingpin .Flag ("profile" , "Use a specific profile from AWS credentials file." ).Short ('p' ).String ()
32
+ limit = kingpin .Flag ("limit" , "Limits total number of messages moved. No limit is set by default." ).Short ('l' ).Default ("0" ).Int ()
33
+ maxBatchSize = kingpin .Flag ("batch" , "The maximum number of messages to move at a time" ).Short ('b' ).Default ("10" ).Int64 ()
33
34
)
34
35
35
36
func main () {
@@ -45,13 +46,16 @@ func main() {
45
46
46
47
kingpin .Parse ()
47
48
48
- sess , err := session .NewSessionWithOptions (
49
- session.Options {
50
- Config : aws.Config {Region : aws .String (* region )},
51
- Profile : * profile ,
52
- SharedConfigState : session .SharedConfigEnable ,
53
- },
54
- )
49
+ options := session.Options {
50
+ Profile : * profile ,
51
+ SharedConfigState : session .SharedConfigEnable ,
52
+ }
53
+
54
+ if region != nil {
55
+ options .Config = aws.Config {Region : aws .String (* region )}
56
+ }
57
+
58
+ sess , err := session .NewSessionWithOptions (options )
55
59
56
60
if err != nil {
57
61
log .Error (color .New (color .FgRed ).Sprintf ("Unable to create AWS session for region \r \n " , * region ))
@@ -163,17 +167,16 @@ func convertSuccessfulMessageToBatchRequestEntry(messages []*sqs.Message) []*sqs
163
167
}
164
168
165
169
func moveMessages (sourceQueueUrl string , destinationQueueUrl string , svc * sqs.SQS , totalMessages int ) {
166
- params : = & sqs.ReceiveMessageInput {
170
+ var params = & sqs.ReceiveMessageInput {
167
171
QueueUrl : aws .String (sourceQueueUrl ),
168
172
VisibilityTimeout : aws .Int64 (2 ),
169
173
WaitTimeSeconds : aws .Int64 (0 ),
170
- MaxNumberOfMessages : aws .Int64 (10 ),
174
+ MaxNumberOfMessages : aws .Int64 (* maxBatchSize ),
171
175
MessageAttributeNames : []* string {aws .String (sqs .QueueAttributeNameAll )},
172
176
AttributeNames : []* string {
173
177
aws .String (sqs .MessageSystemAttributeNameMessageGroupId ),
174
178
aws .String (sqs .MessageSystemAttributeNameMessageDeduplicationId )},
175
179
}
176
-
177
180
log .Info (color .New (color .FgCyan ).Sprintf ("Starting to move messages..." ))
178
181
fmt .Println ()
179
182
0 commit comments