question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Kombu Incorrect parsing of SQS hostname when credentials include a /

See original GitHub issue

Looking at the docs on how to use the AWS SQS queue, it is recommended to use a BROKER_URL of format: sqs://AWS_ACCESS_KEY_ID:AWS_SECRET_ACCESS_KEY@, as seen in your docs: http://docs.celeryproject.org/en/latest/getting-started/brokers/sqs.html

Using the example in your docs:

broker_url = 'sqs://ABCDEFGHIJKLMNOPQRST:ZYXK7NiynGlTogH8Nj+P9nlE73sq3@'

but instead using “Alice’s” credentials from: https://aws.amazon.com/blogs/security/how-to-rotate-access-keys-for-iam-users/

$ aws iam create-access-key --user-name Alice
{
    "AccessKey": {
        "UserName": "Alice",
        "Status": "Active",
        "CreateDate": "2013-09-06T17:09:10.384Z",
        "SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY",
        "AccessKeyId": “AKIAIOSFODNN7EXAMPLE"
    }
}

Your broker_url is now:

broker_url = 'sqs://AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY@'

Full code for the example is now:

from celery import Celery

broker_url = 'sqs://AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY@'

app = Celery('tasks', broker=broker_url)

@app.task
def add(x, y):
    return x + y

Run it with: celery -A tasks worker --loglevel=info

What you then end up with, is a parsing issue, such as:

  File "/usr/local/lib/python3.6/site-packages/kombu/connection.py", line 181, in __init__
    url_params = parse_url(hostname)
  File "/usr/local/lib/python3.6/site-packages/kombu/utils/url.py", line 34, in parse_url
    scheme, host, port, user, password, path, query = _parse_url(url)
  File "/usr/local/lib/python3.6/site-packages/kombu/utils/url.py", line 52, in url_to_parts
    parts.port,
  File "/usr/local/lib/python3.6/urllib/parse.py", line 159, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: 'wJalrXUtnFEMI'`

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
FrenchBencommented, Jan 29, 2018

@georgepsarakis It’d be good to update the documentation to indicate so - Having: sqs://aws_access_key_id:aws_secret_access_key@ as the URL format in the doc is quite misleading.

1reaction
paweladcommented, Nov 23, 2018

For the record, this works:

from urllib.parse import quote_plus

from celery import Celery

aws_access_key = quote_plus('AKIAIOSFODNN7EXAMPLE')
aws_secret_key = quote_plus('wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY')

broker_url = f'sqs://{aws_access_key}:{aws_secret_key}@'

app = Celery('tasks', broker=broker_url)

@app.task
def add(x, y):
    return x + y

I’ll create a PR for the docs ~tomorrow~ at some point ; )

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kombu Documentation - Read the Docs
Kombu is a messaging library for Python. The aim of Kombu is to make messaging in Python as easy as possible by providing...
Read more >
Change history — Kombu 5.2.4 documentation - Celery
When using the SQS broker, FIFO queues with names that ended with the 'f' letter were incorrectly parsed. This is now fixed. Contributed...
Read more >
Troubleshoot QueueDoesNotExist errors when making API ...
A QueueDoesNotExist exception returns when the request is made to the incorrect AWS Region. The software development kit (SDK) and AWS Command ...
Read more >
celery Changelog - pyup.io
Warn about missing hostname only when default one is available (1488). ... Fix: non kombu json message decoding in SQS transport (1306). -...
Read more >
Spring Cloud AWS SQS fails to connect to service endpoint ...
I have received below errors when running Spring Boot Project for AWS SNS i.InstanceMetadataServiceResourceFetcher : Fail to retrieve token ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found