cdk-tweet-queue


Namecdk-tweet-queue JSON
Version 2.0.531 PyPI version JSON
download
home_pagehttps://github.com/eladb/cdk-tweet-queue
SummaryDefines an SQS queue with tweet stream from a search
upload_time2024-03-28 00:21:47
maintainerNone
docs_urlNone
authorElad Ben-Israel<elad.benisrael@gmail.com>
requires_python~=3.8
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Tweet Queue for AWS CDK

This is an [AWS CDK](https://github.com/awslabs/aws-cdk) construct library which
allows you to get a feed of Twitter search results into an SQS queue. It works
by periodically polling the freely available [Twitter Standard Search
API](https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html) and
sending all new tweets to an SQS queue.

Inspired by
[@jlhood](https://github.com/awslabs/aws-serverless-twitter-event-source/commits?author=jlhood)'s
[aws-serverless-twitter-event-source](https://github.com/awslabs/aws-serverless-twitter-event-source)

## Architecture

![](https://github.com/eladb/cdk-tweet-queue/raw/main/images/architecture.png)

1. A CloudWatch Event Rule triggers the poller AWS Lambda function periodically
2. The poller reads the last checkpoint from a DynamoDB table (if exists)
3. The poller issues a Twitter search query for all new tweets
4. The poller enqueues all tweets to an SQS queue
5. The poller stores the ID of the last tweet into the DynamoDB checkpoint table.
6. Rinse & repeat.

## Twitter API Keys

To issue a Twitter search request, you will need to
[apply](https://developer.twitter.com/en/apply-for-access.html) for a Twitter
developer account, and obtain API keys through by defining a [new
application](http://twitter.com/oauth_clients/new).

The Twitter API keys are read by the poller from an [AWS Secrets
Manager](https://aws.amazon.com/secrets-manager/) entry. The entry must contain
the following attributes: `consumer_key`, `consumer_secret`, `access_token_key`
and `access_token_secret` (exact names).

1. Create a new AWS Secrets Manager entry for your API keys
2. Fill in the key values as shown below:
   ![](https://github.com/eladb/cdk-tweet-queue/raw/main/images/secretsmanager.png)
3. Store the key
4. Obtain the ARN of the secret (you will need it soon).

## Usage

Use `npm` to install the module in your CDK project. This will also add it to
your `package.json` file.

```console
$ npm install cdk-tweet-queue
```

Add a `TweetQueue` to your CDK stack:

```python
import { TweetQueue } from 'cdk-tweet-queue';

const queue = new TweetQueue(this, 'TweetStream', {
  // this is the ARN of the secret you stored
  secretArn: 'arn:aws:secretsmanager:us-east-1:1234567891234:secret:xxxxxxxxx'

  // twitter search query
  // see https://developer.twitter.com/en/docs/tweets/search/guides/standard-operators
  query: '#awscdk',

  // optional properties
  intervalMin: 60,          // optional: polling interval in minutes
  retentionPeriodSec: 60,   // optional: queue retention period
  visibilityTimeoutSec: 60, // optional: queue visilibity timeout
});
```

Now, `queue` is an `sqs.Queue` object and can be used anywhere a queue is
accepted. For example, you could process the queue messages using an AWS Lambda
function by setting up an SQS event source mapping.

## Development

The project is managed by [projen](https://github.com/projen/projen) and offers the following commands:

* `yarn projen` - Synthesize the project configuration.
* `yarn compile` - Compile all source code.
* `yarn test` - Run all tests.
* `yarn build` - Complie, test, and package the module.

## Integration test

There is also an integration test that can be executed by running the following commands. You will need to set the `TWEET_QUEUE_SECRET_ARN` environment variable in order for the test to be able to use your Twitter API keys.

```console
$ yarn integ:deploy
```

Don't forget to destroy:

```console
$ yarn integ:destroy
```

You can also run any cdk command on the integration test application by running:

```console
yarn integ <command>
```

## License

Apache-2.0

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eladb/cdk-tweet-queue",
    "name": "cdk-tweet-queue",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "~=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Elad Ben-Israel<elad.benisrael@gmail.com>",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/5a/2c/5c7114d66030382ff14549bc964ab3025c5255b99ddd60d7b362b22fd42e/cdk-tweet-queue-2.0.531.tar.gz",
    "platform": null,
    "description": "# Tweet Queue for AWS CDK\n\nThis is an [AWS CDK](https://github.com/awslabs/aws-cdk) construct library which\nallows you to get a feed of Twitter search results into an SQS queue. It works\nby periodically polling the freely available [Twitter Standard Search\nAPI](https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html) and\nsending all new tweets to an SQS queue.\n\nInspired by\n[@jlhood](https://github.com/awslabs/aws-serverless-twitter-event-source/commits?author=jlhood)'s\n[aws-serverless-twitter-event-source](https://github.com/awslabs/aws-serverless-twitter-event-source)\n\n## Architecture\n\n![](https://github.com/eladb/cdk-tweet-queue/raw/main/images/architecture.png)\n\n1. A CloudWatch Event Rule triggers the poller AWS Lambda function periodically\n2. The poller reads the last checkpoint from a DynamoDB table (if exists)\n3. The poller issues a Twitter search query for all new tweets\n4. The poller enqueues all tweets to an SQS queue\n5. The poller stores the ID of the last tweet into the DynamoDB checkpoint table.\n6. Rinse & repeat.\n\n## Twitter API Keys\n\nTo issue a Twitter search request, you will need to\n[apply](https://developer.twitter.com/en/apply-for-access.html) for a Twitter\ndeveloper account, and obtain API keys through by defining a [new\napplication](http://twitter.com/oauth_clients/new).\n\nThe Twitter API keys are read by the poller from an [AWS Secrets\nManager](https://aws.amazon.com/secrets-manager/) entry. The entry must contain\nthe following attributes: `consumer_key`, `consumer_secret`, `access_token_key`\nand `access_token_secret` (exact names).\n\n1. Create a new AWS Secrets Manager entry for your API keys\n2. Fill in the key values as shown below:\n   ![](https://github.com/eladb/cdk-tweet-queue/raw/main/images/secretsmanager.png)\n3. Store the key\n4. Obtain the ARN of the secret (you will need it soon).\n\n## Usage\n\nUse `npm` to install the module in your CDK project. This will also add it to\nyour `package.json` file.\n\n```console\n$ npm install cdk-tweet-queue\n```\n\nAdd a `TweetQueue` to your CDK stack:\n\n```python\nimport { TweetQueue } from 'cdk-tweet-queue';\n\nconst queue = new TweetQueue(this, 'TweetStream', {\n  // this is the ARN of the secret you stored\n  secretArn: 'arn:aws:secretsmanager:us-east-1:1234567891234:secret:xxxxxxxxx'\n\n  // twitter search query\n  // see https://developer.twitter.com/en/docs/tweets/search/guides/standard-operators\n  query: '#awscdk',\n\n  // optional properties\n  intervalMin: 60,          // optional: polling interval in minutes\n  retentionPeriodSec: 60,   // optional: queue retention period\n  visibilityTimeoutSec: 60, // optional: queue visilibity timeout\n});\n```\n\nNow, `queue` is an `sqs.Queue` object and can be used anywhere a queue is\naccepted. For example, you could process the queue messages using an AWS Lambda\nfunction by setting up an SQS event source mapping.\n\n## Development\n\nThe project is managed by [projen](https://github.com/projen/projen) and offers the following commands:\n\n* `yarn projen` - Synthesize the project configuration.\n* `yarn compile` - Compile all source code.\n* `yarn test` - Run all tests.\n* `yarn build` - Complie, test, and package the module.\n\n## Integration test\n\nThere is also an integration test that can be executed by running the following commands. You will need to set the `TWEET_QUEUE_SECRET_ARN` environment variable in order for the test to be able to use your Twitter API keys.\n\n```console\n$ yarn integ:deploy\n```\n\nDon't forget to destroy:\n\n```console\n$ yarn integ:destroy\n```\n\nYou can also run any cdk command on the integration test application by running:\n\n```console\nyarn integ <command>\n```\n\n## License\n\nApache-2.0\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Defines an SQS queue with tweet stream from a search",
    "version": "2.0.531",
    "project_urls": {
        "Homepage": "https://github.com/eladb/cdk-tweet-queue",
        "Source": "https://github.com/eladb/cdk-tweet-queue"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "419864211a0d7662b283dad2f55fca942e34c18582d330327fbdcc343a88f896",
                "md5": "198a6118ec3744d1f067151c34135f7d",
                "sha256": "fc67286fe72272b3627c091f042430e812ff1c3e79c7cc6a8569e4028fdbcab8"
            },
            "downloads": -1,
            "filename": "cdk_tweet_queue-2.0.531-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "198a6118ec3744d1f067151c34135f7d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "~=3.8",
            "size": 105857,
            "upload_time": "2024-03-28T00:21:41",
            "upload_time_iso_8601": "2024-03-28T00:21:41.984626Z",
            "url": "https://files.pythonhosted.org/packages/41/98/64211a0d7662b283dad2f55fca942e34c18582d330327fbdcc343a88f896/cdk_tweet_queue-2.0.531-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5a2c5c7114d66030382ff14549bc964ab3025c5255b99ddd60d7b362b22fd42e",
                "md5": "60694e6bb5be01ea2992d52d43869813",
                "sha256": "9256fef639cf97602d95910f6d7a14fa12645b52953144a401b40cba94a39e8c"
            },
            "downloads": -1,
            "filename": "cdk-tweet-queue-2.0.531.tar.gz",
            "has_sig": false,
            "md5_digest": "60694e6bb5be01ea2992d52d43869813",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "~=3.8",
            "size": 107422,
            "upload_time": "2024-03-28T00:21:47",
            "upload_time_iso_8601": "2024-03-28T00:21:47.525520Z",
            "url": "https://files.pythonhosted.org/packages/5a/2c/5c7114d66030382ff14549bc964ab3025c5255b99ddd60d7b362b22fd42e/cdk-tweet-queue-2.0.531.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-28 00:21:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "eladb",
    "github_project": "cdk-tweet-queue",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cdk-tweet-queue"
}
        
Elapsed time: 0.26330s