简体   繁体   English

从S3存储桶上传/下载数据

[英]Upload/download data from S3 bucket

I am trying to upload one file from my local machine however I get the following error: 我正在尝试从本地计算机上载一个文件,但是出现以下错误:

AWS Error Code: AccessDenied AWS错误代码:AccessDenied

Could you please help me how to establish the connection to AWS S3 bucket? 您能否帮助我如何建立与AWS S3存储桶的连接?

I have used below code for uploading the file. 我已使用以下代码上传文件。

import com.amazonaws.auth._
import com.amazonaws.services.s3.AmazonS3Client

val bucketName = "bucketname"

val fileToUpload = new File("C:\\text.csv") 
val AWS_ACCESS_KEY = "....."
val AWS_SECRET_KEY = "........."

val yourAWSCredentials = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)
val amazonS3Client = new AmazonS3Client(yourAWSCredentials)
// This will create a bucket for storage
//amazonS3Client.createBucket(bucketName)
amazonS3Client.putObject(bucketName, "text.csv", fileToUpload)

You are getting the access denied error so your code tries to connect to S3 correctly. 您遇到access denied错误,因此您的代码尝试正确连接到S3。 The issue, at this moment, is not in your code and it is in your security clearance. 目前,问题不在您的代码中,而是在您的安全许可中。

So in AWS, you should go to IAM and check the security policies related to your access and secret key and see why you can not access to your S3. 所以在AWS,你应该去IAM,并检查与您的安全策略accesssecret密钥,看看为什么你不能访问您的S3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM