Module: Jets::Job::Dsl::SqsEvent
- Defined in:
- lib/jets/job/dsl/sqs_event.rb
Instance Method Summary collapse
- #declare_sqs_queue(props) ⇒ Object
- #default_sqs_iam_policy(queue_name_arn = '*') ⇒ Object
-
#full_sqs_queue_arn(queue_name) ⇒ Object
Expands simple queue name to full arn.
- #sqs_event(queue_name, options = {}) ⇒ Object
Instance Method Details
#declare_sqs_queue(props) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/jets/job/dsl/sqs_event.rb', line 67 def declare_sqs_queue(props) props ||= {} # since options.delete(:queue_properties) can be nil r = Jets::Resource::Sqs::Queue.new(props) with_fresh_properties do resource(r.definition) # add associated resource immediately end end |
#default_sqs_iam_policy(queue_name_arn = '*') ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/jets/job/dsl/sqs_event.rb', line 86 def default_sqs_iam_policy(queue_name_arn='*') { action: ["sqs:ReceiveMessage", "sqs:DeleteMessage", "sqs:GetQueueAttributes"], effect: "Allow", resource: queue_name_arn, } end |
#full_sqs_queue_arn(queue_name) ⇒ Object
Expands simple queue name to full arn. Example:
hello-queue
To:
arn:aws:sqs:us-west-2:112233445566:hello-queue
80 81 82 83 84 |
# File 'lib/jets/job/dsl/sqs_event.rb', line 80 def full_sqs_queue_arn(queue_name) return queue_name if queue_name.include?("arn:aws:sqs") "arn:aws:sqs:#{Jets.aws.region}:#{Jets.aws.account}:#{queue_name}" end |
#sqs_event(queue_name, options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jets/job/dsl/sqs_event.rb', line 40 def sqs_event(queue_name, ={}) if queue_name.to_s =~ /generate/ queue_arn = "!GetAtt {namespace}SqsQueue.Arn" default_iam_policy = default_sqs_iam_policy('*') # Dont have access to full ARN on initial creation declare_sqs_queue(.delete(:queue_properties)) # delete to avoid using them for event_source_mapping elsif queue_name.include?('!Ref') # reference shared resource queue_arn = queue_name default_iam_policy = default_sqs_iam_policy('*') # Dont have access to full ARN on initial creation else # existing queue: short name or full arn queue_arn = full_sqs_queue_arn(queue_name) default_iam_policy = default_sqs_iam_policy(queue_arn) end # Create iam policy allows access to queue # Allow disabling in case use wants to add permission application-wide and not have extra IAM policy iam_policy_props = .delete(:iam_policy) || @iam_policy || default_iam_policy iam_policy(iam_policy_props) unless iam_policy_props == :disable props = # by this time options only has EventSourceMapping properties default = { event_source_arn: queue_arn } props = default.merge(props) event_source_mapping(props) end |