1
votes

I'm building an app with Amplify where one of the functions generates PDF. I would like to save this PDF in S3 which is also created through Amplify. Accessing S3 from the front-end side is well documented but no mention for doing it from Lambda. In that Lambda function, I'm accessing DynamoDB without any problems so aws-sdk is configured.

I can configure the IAM role and bucket manually, but is there the Right Way of doing it with Amplify?

1
You will find this helpful: stackoverflow.com/a/56452387/7550592 - Yik San Chan

1 Answers

0
votes

If you want to access to s3 bucket that is created by amplify within lambda function that is also created by amplify,

You can find your bucket name in lambda environment variable.

# index.py

import os

def index():
    print(os.environ)

This will print out something like

AWS_LAMBDA_FUNCTION_VERSION: "$LATEST",
AWS_SESSION_TOKEN:"Your Token",
STORAGE_{YOUR_STORAGE_NAME_IN_AMPLIFY}_BUCKETNAME: "ACTUAL_BUCKETNAME_CREATED_BY_AMPLIFY",
LAMBDA_TASK_ROOT: "/var/task",
...

After you get your bucket name, the rest process is just setting up boto3 client with your configuration and doing the task you want.