how to upload files to s3 without using Access key from EC2 through React Js

0

I want to upload the files to s3 without using access key from EC2 through react js , how can i do this using IAM or suggest me best practice to do that without exposing credentials

2 Answers
0

Hello.

If the execution environment is EC2, you can access S3 using an IAM role.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#working-with-iam-roles

profile picture
EXPERT
answered 3 months ago
  • i have attach IAM role to AWS which provide access to S3 ,kindly suggest me sdk or sample to code to upload files directly to S3

0

Hi. We can also use IMDS v2 on EC2 to get credential.
https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html

<Example commend>.

  1. to get token.
    TOKEN= 'curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds:21600"'

  2. to get credential from IAM role.
    curl -H "X-aws-ec2-metadata-token:$TOKEN" -v http://169.254.169.254/latest/meta-data/iam/security-credentials/<IAM-role>

But IMDS2 looks like it does not support recat js.
https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/use-a-supported-sdk-version-for-imdsv2.html

AWS
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions