1
votes

I am trying to follow the aws lambda tutorial, currenty at: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

I am on the step to "add permissions to the function policy"

It says to: " Run the following Lambda CLI add-permission command to grant Amazon S3 service principal (s3.amazonaws.com) permissions to perform the lambda:InvokeFunction action. Note that permission is granted to Amazon S3 to invoke the function only if the following conditions are met:

  • An object-created event is detected on a specific bucket.

  • The bucket is owned by your account. If you delete a bucket, it is possible for another account to create a bucket with the same ARN. "

and then it gives a command line command to enter:

aws lambda add-permission --function-name CreateThumbnail --principal s3.amazonaws.com --statement-id s3invoke --action "lambda:InvokeFunction" --source-arn arn:aws:s3:::sourcebucket --source-account account-id

I do not own the bucket I want to trigger on. It is an already established bucket set up by my company and I've been tasked with learning lambda and triggering when a file is uploaded to it.

How do I get the account id to use and can I use an account id other than my own in that command?

Also, is the sourcebucket arn always "arn:aws:s3:::?" Is it diplayed somewhere?

2

2 Answers

2
votes

Christopher, You'll need to enter the account id in which bucket is already created by your company. Moreover, you'll definitely need to enter the arn (amazon resource name) of that bucket for which you're setting up the trigger.

This is how ARN looks like:

arn:aws:s3:::bucket-name

You'll find the account id in account settings on AWS console.

0
votes

For any bucket's ARN, click on the bucket's row anywhere, it'll open a slide window on right and you can see the button "Copy bucket ARN", you can see the format is always 'arn:aws:s3:::l'

QUESTION: Could you see any trigger for S3 automatically generated inside Lambda function after this command? I cannot and it should be there. Like I see Last modified column updated but cannot see any trigger generated automatically.