Class: Aws::SNS::ExtendedClient

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Extended
Defined in:
lib/aws/sdk/extended/sns.rb

Overview

Amazon SNS extended client, API-compatible with Aws::SNS::Client from the aws-sdk-sns gem, invokes service methods on Amazon SNS with extended functionality to support large payloads.

Constant Summary

Constants included from Extended

Extended::DEFAULT_S3_MUTEX, Extended::EMPTY_ARRAY, Extended::EMPTY_HASH, Extended::EMPTY_STRING, Extended::LEGACY_RESERVED_ATTRIBUTE_NAME, Extended::MAX_ALLOWED_ATTRIBUTES, Extended::MESSAGE_SIZE_THRESHOLD, Extended::RECEIPT_HANDLE_FORMAT, Extended::RESERVED_ATTRIBUTE_NAME, Extended::S3_BUCKET_NAME_MARKER, Extended::S3_KEY_ATTRIBUTE_NAME, Extended::S3_KEY_MARKER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Extended

default_s3_client, message_size, store_large_message

Constructor Details

#initialize(sns_client, bucket: ENV.fetch("AWS_EXTENDED_CLIENT_S3_BUCKET"), s3_client: Extended.default_s3_client, always_through_s3: false, payload_size_threshold: MESSAGE_SIZE_THRESHOLD) ⇒ ExtendedClient

Constructs a new SNS extended client, where all SNS service calls are forwarded to sns_client, and calls to S3 to store large payloads are forwarded to s3_client using the bucket specified by bucket, and not just payloads which are bigger than the number of bytes specified by payload_size_threshold. This can be circumvented by always_through_s3 though, which will cause it to store all payloads in the S3 bucket. : ( | SNS::Client, | ?bucket: String, | ?s3_client: S3::Client, | ?always_through_s3: bool, | ?payload_size_threshold) -> void



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aws/sdk/extended/sns.rb', line 35

def initialize(
  sns_client,
  bucket: ENV.fetch("AWS_EXTENDED_CLIENT_S3_BUCKET"),
  s3_client: Extended.default_s3_client,
  always_through_s3: false,
  payload_size_threshold: MESSAGE_SIZE_THRESHOLD
)
  @sns_client = sns_client
  @s3_client = s3_client
  @bucket = bucket
  @always_through_s3 = always_through_s3
  @payload_size_threshold = payload_size_threshold
  super(sns_client)
end

Instance Attribute Details

#always_through_s3Object (readonly)

: bool



20
21
22
# File 'lib/aws/sdk/extended/sns.rb', line 20

def always_through_s3
  @always_through_s3
end

#bucketObject (readonly)

: String



18
19
20
# File 'lib/aws/sdk/extended/sns.rb', line 18

def bucket
  @bucket
end

#payload_size_thresholdObject (readonly)

: Integer



22
23
24
# File 'lib/aws/sdk/extended/sns.rb', line 22

def payload_size_threshold
  @payload_size_threshold
end

#s3_clientObject (readonly)

: S3::Client



16
17
18
# File 'lib/aws/sdk/extended/sns.rb', line 16

def s3_client
  @s3_client
end

#sns_clientObject (readonly)

: SNS::Client



14
15
16
# File 'lib/aws/sdk/extended/sns.rb', line 14

def sns_client
  @sns_client
end

Instance Method Details

#freezeObject

: void



50
51
52
53
54
55
# File 'lib/aws/sdk/extended/sns.rb', line 50

def freeze #: void
  @sns_client.freeze
  @s3_client.freeze
  @bucket.freeze
  super
end

#publish(params = {}) ⇒ Object

Same functionality as Client#publish, will store the message payload in S3 if all conditions match. : (Hash[Symbol, untyped], *untyped) -> SNS::Client::_PublishResponseSuccess



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/aws/sdk/extended/sns.rb', line 60

def publish(params = {}, *)
  input = Aws::SNS::Types::PublishInput.new(params)

  return super unless input.message && (@always_through_s3 || large_message?(input))

  # TODO: raise error for JSON payloads: https://github.com/awslabs/amazon-sns-java-extended-client-lib/blob/main/src/main/java/software/amazon/sns/AmazonSNSExtendedClient.java#L184
  if input.message_structure == "json"
    raise Extended::Error, "SNS extended client does not support sending JSON messages"
  end

  params[:message_attributes], params[:message] =
    Extended.store_large_message(
      input.message_attributes,
      input.message, @s3_client, @bucket
    )

  super
end