Skip to content

Commit

Permalink
add functions CheckQueueExists CheckBucketExists
Browse files Browse the repository at this point in the history
  • Loading branch information
bpeng committed Nov 26, 2024
1 parent f2c17e5 commit 56c71e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ func (s *S3) PutWithMetadata(bucket, key string, object []byte, metadata Meta) e
return err
}

// checks if the given S3 bucket exists.
func (s *S3) CheckBucketExists(bucketName string) error {
// Check if the bucket exists.
_, err := s.client.HeadBucket(context.TODO(), &s3.HeadBucketInput{
Bucket: aws.String(bucketName),
})

return err
}

// Exists checks if an object for key already exists in the bucket.
func (s *S3) Exists(bucket, key string) (bool, error) {

Expand Down
10 changes: 10 additions & 0 deletions aws/sqs/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ func (s *SQS) CreateQueue(queueName string, isFifoQueue bool) (string, error) {
return aws.ToString(queue.QueueUrl), err
}

// checks if the given SQS queue exists.
func (s *SQS) CheckQueueExists(queueName string) error {
// Check if the queue exists.
_, err := s.client.GetQueueUrl(context.TODO(), &sqs.GetQueueUrlInput{
QueueName: aws.String(queueName),
})

return err
}

// DeleteQueue deletes an Amazon SQS queue.
func (s *SQS) DeleteQueue(queueUrl string) error {
_, err := s.client.DeleteQueue(context.TODO(), &sqs.DeleteQueueInput{
Expand Down

0 comments on commit 56c71e3

Please sign in to comment.