Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: allow queues in shoryuken.yml to be provided as ARN values #602

Closed
nippysaurus opened this issue May 22, 2020 · 6 comments
Closed

Comments

@nippysaurus
Copy link

I'm writing a CDK template for deploying an application with a lot of Shoryuken queues. Everything in AWS is using the ARN, but Shoryuken only works with URL and not ARN. These values are easy translated from one format to the other, but with so many queues it would still be a lot of mapping values in my code to do the translation. It would be super convenient if Shoryuken would do this for me.

Here you can see how the AWS CDK template does the mapping

@phstc
Copy link
Collaborator

phstc commented May 22, 2020

Hi @nippysaurus

Shoryuken can work with queue name or URL.

You can get queueUrl and queueName with CDK.

You could also output then.

new cdk.CfnOutput(this, "QUEUE_URL", { value: queue.queueURL });
new cdk.CfnOutput(this, "QUEUE_NAME", { value: queue.queueName });

The AWS SDK Ruby expects queue_url for interacting with a queue, so the conversion is required.

There are also some alternatives, for example, converting from ARN to URL or Name in your shoryuken.yml, it is an ERB. You can add code in there. Also, instead of adding queues via the shoryuken.yml you could add them programmatically Shoryuken.add_queue(...) in an initializer.

I don't recall previous requests for that, but I'm open to pull requests if the logic makes sense in case you are interested in submitting one.

@nippysaurus
Copy link
Author

Yeah it's easy to do the mapping, but with the URL and ARN being so easily translated it would be nice to be able to supply either and have Shoryuken figure out what it is.

I took your advice and did the mapping in the config.

# config/initializers/shoryuken.rb
def SqsArnToUrl(arn_str)
  return unless arn_str

  arn = Aws::ARNParser.parse(arn_str)

  raise "please pass an shoryuken queue ARN with region, account_id, and resource values (#{arn_str})" if [
    arn.region,
    arn.account_id,
    arn.resource
  ].any? { |value| value == "" || value == nil }

  `https://sqs.#{arn.region}.amazonaws.com/#{arn.account_id}/#{arn.resource}`
end

It would be great if this was in the Shoryuken framework though.

@phstc
Copy link
Collaborator

phstc commented May 25, 2020

@nippysaurus yay I'm happy it worked! The code makes sense to me. Would you like to submit a PR?

name_or_url will need to be changed to name_or_url_or_arn, but it is fine. We should only check for the arn if the string starts with arn:.

@phstc
Copy link
Collaborator

phstc commented May 25, 2020

Minor code tweak:

def queue_url_from_arn(arn_str)
  arn = Aws::ARNParser.parse(arn_str)
  required = [arn.region, arn.account_id, arn.resource]

  raise "please pass an shoryuken queue ARN with region, account_id, and resource values (#{arn_str})" if required.any?(&:empty?)

  "https://sqs.#{arn.region}.amazonaws.com/#{arn.account_id}/#{arn.resource}"
rescue Aws::Errors::InvalidARNError
  raise "Invalid ARN: #{arn_str}"
end

@nippysaurus
Copy link
Author

Thanks @phstc :) I'll try and put in some effort to get an MR up this week.

@phstc
Copy link
Collaborator

phstc commented Aug 8, 2020

Added to 5.0.5

#603 (comment)

@phstc phstc closed this as completed Aug 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants