Lambda trigger from a specific tag key value of S3 Object

0

Hi Team,

Our use case is that, we will be uploading S3 objects with specific tag values and based on that specific tag value lambda function need to be triggered and it should move that object with specific tag value to another bucket.

Kindly share the lambda function code to achieve this.

1回答
0

Hi there,

You can check the objects uploaded under a certain prefix and file extensions and in your lamdba, filter for the specific tags see here on how to fetch the object tags. Do change it for the programming language you are using :)

These are the list of options for s3 tigger. Enter image description here

Below is a lambda code you can use to copy from source to destination bucket(replace with the actual bucket values), here I am using the copy_object method

def lambda_handler(event, context):

    session_aws = boto3.Session()
    s3_client_aws = session_aws.client("s3")

    source_bucket_objects = s3_client_aws.list_objects_v2(
        Bucket=f"{sourcebucketname}", Prefix=f"{source_prefix}"
    )

    # add additional logic as    

    resp = s3_client_aws.copy_object(
        CopySource=f"{source_bucket}",
        Bucket=f"{dest_bucket}",
        Key=content["Key"],
    )
    # check response errors 
    except Exception:
        # handle errors

Also check this doc on the how to do it. Here is another lambda example (in different languages) from aws doc above code I posted is just an slight deviation

HTH

AWS
jay-aws
回答済み 1ヶ月前
profile picture
エキスパート
レビュー済み 1ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ