This CloudFormation registry extension resource type allows you to specify S3 bucket notifications one at a time, in a way that does not result in a circular dependency error in your template.
Note that this resource intentionally introduces drift into your template,
since the official way to configure bucket notifications is to specify them as
part of the AWS::S3::Bucket resource.
Resources:
Queue:
Type: AWS::SQS::Queue
Bucket:
Type: AWS::S3::Bucket
Notification:
Type: AwsCommunity::S3::BucketNotification
Properties:
Id: MyNotification
Events:
- s3:ObjectCreated:*
Filters:
- Name: suffix
Value: gif
BucketArn: !GetAtt Bucket.Arn
TargetType: Queue
TargetArn: !GetAtt Queue.Arn
DependsOn:
- Bucket
- QueueOpen two tabs in your terminal.
Create a virtual environment.
cd resources/BucketNotification
python3 -m venv .env
source .env/bin/activate
pip install -r requirements-dev.txtIn the other tab, run SAM local:
cd resources/BucketNotification
source .env/bin/activaate
sam local start-lambdaKeep in mind that SAM local testing only simulates lambda locally, it will make SDK calls into your account and create resources!
Create the setup stack so that contract tests have something to interact with in your account.
aws cloudformation create-stack --stack-name bucketnotification-setup \
--template-body file://test/setup.ymlIn the first tab:
./run-test.shIf you don't have a default profile set up on your machine, you can do this:
AWS_PROFILE=my-profile ./run-test.shThe run-test.sh script runs pylint and does a cfn submit --dry-run, which is necessary to create the build folder that SAM relies on.
There is also an integ test you can run to test the SDK calls without using SAM. It also creates resources in your account.
cd src
python3 run_integ_test.py --profile your-aws-profile-name