I have the below batch script for creating my Lambda function via the AWS CLI:
rem -----------------------------------------
rem create or update the lambda function
aws lambda create-function ^
--function-name %LAMBDA_FUNCTION_NAME% ^
--runtime python3.9 ^
--role %LAMBDA_ROLE_ARN% ^
--handler %LAMBDA_HANDLER% ^
--zip-file fileb://%LAMBDA_ZIP_FILE% ^
--profile %AWS_PROFILE% ^
--region %REGION% ^
--timeout 180 ^
--memory-size 1024 ^
--layers %LAMBDA_ARN_LAYER% ^
--environment Variables={PYTHONPATH=python/lib}
@echo on
@echo Deployed the AWS Lambda function %LAMBDA_FUNCTION_NAME% in region %REGION%
@echo off
rem -----------------------------------------
rem add S3 trigger
aws lambda create-event-source-mapping ^
--function-name %LAMBDA_FUNCTION_NAME% ^
--event-source-arn arn:aws:s3:::%S3_BUCKET_NAME% ^
--batch-size 1 ^
--starting-position "LATEST" ^
--profile %AWS_PROFILE% ^
--region %REGION% ^
--event-source-request-parameters Events=s3:ObjectCreated:* Filter='{"Key": {"Suffix": [".MF4",".MFC",".MFE",".MFM"]}}'
However, I get an error for the last part of the create-function:
Unknown options: --event-source-request-parameters, Filter='{Key:, {Suffix:, [.MF4,.MFC,.MFE,.MFM]}}', Events=s3:ObjectCreated:*
In what way is my syntax wrong? I want to use my S3 bucket as the trigger whenever a file with one of the file extensions listed is uploaded.
S3 event notification doesn't need an event source mapping. You should use the following CLI command instead to use your S3 bucket as the trigger:
aws s3api put-bucket-notification-configuration --bucket S3_BUCKET_NAME ...