This AWS CDK configuration sets up an automated workflow to trigger a specific Lambda function based on the prefix of files uploaded to Amazon S3. Using the SNS service with a filter policy, it directs events to the appropriate Lambda function efficiently.
-
Install AWS CDK and Bootstrap Your AWS Account in a Specific Region
npm install -g aws-cdk cdk bootstrap
-
Create a
.env
File with Your AWS Account IDAWS_ACCOUNT_ID=YOUR_ACCOUNT_ID
-
Install Dependencies
-
Run the following command in the project root to install all dependencies:
yarn
-
Then navigate to the functions folder to install the required node modules for Lambda functions:
cd ./functions yarn
-
-
Deploy to AWS
-
Use this command to deploy all stacks to AWS:
cdk deploy --all
-
After running the above commands, an S3 bucket will be created. Upload a file to one of the designated folders (e.g., folder1 or folder2). Depending on the folder, the corresponding Lambda function (e.g., lambda1 or lambda2) will be triggered automatically.