Run Fargate task with S3 upload event
Project description
@sudocdkconstructs/s3-run-fargate-task
It's a very common AWS pattern to run a Fargate task when a file is uploaded to a S3 bucket. Usually developers create a Lambda function that is connected to S3 event notifications and starts the Fargate task. This construct uses a little different approach. It enables S3 EventBridge notifications in the bucket and creates a rule that runs the Fargate task. It passes the bucket name and object key to the container as an environment variables. Notice that it does not required a Lambda function.
Install
TypeScript/JavaScript:
npm i @sudocdkconstructs/s3-run-fargate-task
Python:
pip install sudocdkconstructs.s3-run-fargate-task
How to use
const bucket = new cdk.aws_s3.Bucket(this, 'Bucket', {
bucketName: 's3-fargate-bucket'
})
new S3RunFargateTask(this, 'S3RunFargateTask', {
bucket,
ruleName: 'cdk-run-fargate-rule',
clusterName: 'FargateCluster',
ruleDescription: 's3 event runs fargate task',
taskDefinitionArn: 'arn:aws:ecs:us-east-1:002020202:task-definition/FargateTask:9',
containerName: 'processContainer',
subnetIds: ['subnet-0001', 'subnet-00002'],
securityGroups: ['sg-00001']
})
The bucket name will be in the container environment variable BUCKET
and the object key in the KEY
variable.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sudocdkconstructs.s3-run-fargate-task-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b14593831320b9c4a774e8e00e2189d1f2640a42f2a3cb6817aaaaeeb79c2bd5 |
|
MD5 | 33bb3068ea17d85e300f3a87fc68de89 |
|
BLAKE2b-256 | 2a978c11b0fa907ae095c4e72d53f3d3cfa8243623e0f18a59e6cfa802f36b62 |
Hashes for sudocdkconstructs.s3_run_fargate_task-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcc8cda4c957be9ea50f6c1b5e355a4ef423fa850438d64033d55e2616b2b83c |
|
MD5 | 4dc722d40b11dcc5d7a49c33285ae3ca |
|
BLAKE2b-256 | af1f7acc337799d1e5201a42f8c1a8f845a119e20051087c5624e55b3ca9212d |