Skip to content

Using AWS CDK Python to create Simple message Queue Service (SQS) and subscribe to the message queue; and Simple Notification Service (SNS)

License

Notifications You must be signed in to change notification settings

gabepublic/aws-cdk-py-sqs-sns-01

Repository files navigation

aws-cdk-py-sqs-sns-01

Using AWS CDK Python to create Simple message Queue Service (SQS) and subscribe to the message queue; and Simple Notification Service (SNS)

Prerequisite

Same as aws-cdk-py-s3-01

Build and Deploy

  • [Skip Create Project] This repo contains artifacts generated by the following codes:
$ cd ~/projects
$ mkdir aws-cdk-py-sqs-sns-01
$ cd aws-cdk-py-sqs-sns-01
$ cdk init sample-app --language python
  • Create python virtual environment
$ virtualenv .venv
$ source .venv/bin/activate

(.venv) $ pip install -r requirements.txt
  • Set Policy; the following policies are needed minimally to cdk deploy, and they are needed for CloudFormation & S3.
    • Unless, the IAM user (configured above in the ~/.aws/credential and aws_access_key_id key) belongs to the Administrators group.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "cloudformation:DescribeStacks",
                "cloudformation:CreateChangeSet",
                "cloudformation:DescribeChangeSet",
                "cloudformation:ExecuteChangeSet",
                "cloudformation:DescribeStackEvents",
                "cloudformation:DeleteChangeSet",
                "cloudformation:DeleteStack",
                "cloudformation:GetTemplate",
                "sqs:*",
                "sns:*"
            ],
            "Resource": "*"
        }
    ]
}
(.venv) $ cdk synth
  • Deploy
(.venv) $ cdk deploy

# to speed up the deployment time 
(.venv) $ cdk deploy --hotswap

Test

  • Install testing packages
(.venv) $ cd ~/projects/aws-cdk-py-sqs-sns-01

(.venv) $ pip install -r requirements-dev.txt
  • The test file: ./tests/unit/test_aws_cdk_py_sqs_sns_01_stack.py

  • Test Results as of 2022, July 17

(.venv) $ cd ~/projects/aws-cdk-py-sqs-sns-01
(.venv) $ pytest
=========================================================== test session starts ============================================================
platform linux -- Python 3.8.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/gabe/projects/aws-cdk-py-sqs-sns-01
collected 2 items
tests/unit/test_aws_cdk_py_sqs_sns_01_stack.py ..                                                                                    [100%]
============================================================ 2 passed in 6.50s =============================================================
(.venv) $

Cleanup

  • Cleanup
(.venv) $ cdk destroy

Output:

Are you sure you want to delete: aws-cdk-py-sqs-sns-01 (y/n)? y
aws-cdk-py-sqs-sns-01: destroying...

 ✅  aws-cdk-py-sqs-sns-01: destroyed

(.venv) $
  • Additional cleanup not done by the the cdk destroy

    • CloudWatch Log group; go to AWS Console "CloudWatch > Logs > Log groups" and delete two log groups:
      • /aws/lambda/<stack-name>-CustomCDKBucketDeployment<unique-id>
      • /aws/lambda/<stack-name>-CustomS3AutoDeleteObjectsCustomResourcePr-<unique-id>
  • Exit virtualenv

(.venv) $ deactivate
$

About

Using AWS CDK Python to create Simple message Queue Service (SQS) and subscribe to the message queue; and Simple Notification Service (SNS)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published