我目前使用如下方式将单个对象上传到S3:
var options = {
Bucket: bucket,
Key: s3Path,
Body: body,
ACL: s3FilePermissions
};
S3.putObject(options,
function (err, data) {
//console.log(data);
});
Run Code Online (Sandbox Code Playgroud)
但是当我有一个大型资源文件夹时,我使用AWS CLI工具.
我想知道,是否有一种原生方式与aws sdk做同样的事情(将整个文件夹上传到s3)?
我正在尝试为使用aws-sdkNPM模块的应用程序编写一些测试覆盖,该模块将事物推送到SQS队列,但我不确定如何正确地模拟事物.
这是我到目前为止的测试:
var request = require('superagent'),
expect = require('chai').expect,
assert = require('chai').assert,
sinon = require('sinon'),
AWS = require('aws-sdk'),
app = require("../../../../app");
describe("Activities", function () {
describe("POST /activities", function () {
beforeEach(function(done) {
sinon.stub(AWS.SQS.prototype, 'sendMessage');
done();
});
afterEach(function(done) {
AWS.SQS.prototype.sendMessage.restore();
done();
});
it("should call SQS successfully", function (done) {
var body = {
"custom_activity_node_id" : "1562",
"campaign_id" : "318"
};
reqest
.post('/v1/user/123/custom_activity')
.send(body)
.set('Content-Type', 'application/json')
.end(function(err, res) {
expect(res.status).to.equal(200)
assert(AWS.SQS.sendMessage.calledOnce);
assert(AWS.SQS.sendMessage.calledWith(body));
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
我看到的错误是:
1) Activities POST …Run Code Online (Sandbox Code Playgroud) 使用AWS SDK gem,我可以轻松获取给定一些参数的对象URL.
例:
credentials = Aws::Credentials.new(ENV['S3_KEY'], ENV['S3_SECRET'])
s3 = Aws::S3::Resource.new(
credentials: credentials,
region: ENV['S3_REGION_KEY']
)
object = s3.bucket('my-bucket').object('path/to/file.ext')
url = object.public_url
Run Code Online (Sandbox Code Playgroud)
给定一个公共URL,我可以将其反转以获得一个Aws::S3::Object?是否有使用此SDK的方法?或者我应该手动拆分URL?(我宁愿避免这种情况.)
使用AWS SDK for Node,为什么在尝试删除不存在的对象时(即S3键错误),我不会收到错误?
另一方面,如果我指定不存在的存储桶,则会产生错误.
如果考虑以下Node程序,该Key参数会列出存储桶中不存在的密钥,但error回调的参数为null:
var aws = require('aws-sdk')
function getSetting(name) {
var value = process.env[name]
if (value == null) {
throw new Error('You must set the environment variable ' + name)
}
return value
}
var s3Client = new aws.S3({
accessKeyId: getSetting('AWSACCESSKEYID'),
secretAccessKey: getSetting('AWSSECRETACCESSKEY'),
region: getSetting('AWSREGION'),
params: {
Bucket: getSetting('S3BUCKET'),
},
})
picturePath = 'nothing/here'
s3Client.deleteObject({
Key: picturePath,
}, function (err, data) {
console.log('Delete object callback:', err)
})
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AWS Lambda函数中的Amazon SES发送电子邮件,为此我遇到以下错误.
AccessDenied:用户
arn:aws:sts::XXXXX:assumed-role/lambda_basic_execution/awslambda_XXXX' is not authorized to performses:资源上的SendEmail`arn:aws:ses:us-west-2:XXX:identity /example@example.com'
我已经批准了
用于IAM角色的"ses:SendEmail","ses:SendRawEmail".
关于如何使用aws SDK在java中发送Textmessage的官方aws文档非常简单.
但是,当发送如底部示例中所示的消息时,我收到错误 User: arn:aws:iam::xxx:user/sms-testing is not authorized to perform: SNS:Publish on resource: +999999999
请注意,+999999999是传递给该电话号码.withPhoneNumber()的呼叫,因此AWS API抱怨我的IAM用户没有必要的权限SNS:Publish的消息到与该电话号码资源.
我的问题:如何创建一个能够通过java SDK发送短信通知的IAM用户?目前,看起来我必须为我发送消息的每个号码创建一个权限,这看起来很奇怪,很难维护.
我正在尝试创建一个S3存储桶并立即为其分配一个lambda通知事件.
这是我写的节点测试脚本:
const aws = require('aws-sdk');
const uuidv4 = require('uuid/v4');
aws.config.update({
accessKeyId: 'key',
secretAccessKey:'secret',
region: 'us-west-1'
});
const s3 = new aws.S3();
const params = {
Bucket: `bucket-${uuidv4()}`,
ACL: "private",
CreateBucketConfiguration: {
LocationConstraint: 'us-west-1'
}
};
s3.createBucket(params, function (err, data) {
if (err) {
throw err;
} else {
const bucketUrl = data.Location;
const bucketNameRegex = /bucket-[a-z0-9\-]+/;
const bucketName = bucketNameRegex.exec(bucketUrl)[0];
const params = {
Bucket: bucketName,
NotificationConfiguration: {
LambdaFunctionConfigurations: [
{
Id: `lambda-upload-notification-${bucketName}`,
LambdaFunctionArn: 'arn:aws:lambda:us-west-1:xxxxxxxxxx:function:respondS3Upload',
Events: ['s3:ObjectCreated:CompleteMultipartUpload']
},
] …Run Code Online (Sandbox Code Playgroud) 我正在从 React 客户端处理 aws s3 照片上传,但遇到以下错误:
TypeError: Cannot read property 'byteLength' of undefined
我假设上传对象存在缺陷,但我相信 s3/cognito 配置可能有问题,因为当我调用s3.listObjects. 我正在关注这些文档 - https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photo-album-full.html
有什么想法吗?
uploadPhoto() {
const files = document.getElementById("photoUpload").files;
if (!files.length) {
return alert("Please choose a file to upload first.");
}
const file = files[0];
const fileName = file.name;
const albumPhotosKey = encodeURIComponent('screenshots') + "/";
const photoKey = albumPhotosKey + fileName;
// Use S3 ManagedUpload class as it supports multipart uploads
const upload = new AWS.S3.ManagedUpload({
params: {
Bucket: <Bucket Name>, …Run Code Online (Sandbox Code Playgroud) 当我使用aws-sdkNode.js 18.x 模块时:
const aws = require("aws-sdk");
exports.handler = async (event) => {
console.log('Hello!');
// some code
};
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
{
"errorType": "ReferenceError",
"errorMessage": "require is not defined in ES module scope, you can use import instead",
"trace": [
"ReferenceError: require is not defined in ES module scope, you can use import instead",
" at file:///var/task/index.mjs:1:13",
" at ModuleJob.run (node:internal/modules/esm/module_job:193:25)",
" at async Promise.all (index 0)",
" at async ESMLoader.import (node:internal/modules/esm/loader:530:24)",
" at async _tryAwaitImport (file:///var/runtime/index.mjs:921:16)",
" at async …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AWS php sdk,并设置了一些问题.当我运行需要自动加载器的php脚本时,我收到此错误:
Parse error: syntax error, unexpected '$value' (T_VARIABLE) in /[directory path]/Aws/functions.php on line 36
Run Code Online (Sandbox Code Playgroud)
我看了那个文件,第36行就是那个开头的if ($pred($value)).
function filter($iterable, callable $pred){
foreach ($iterable as $value) {
if ($pred($value)) {
yield $value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
不确定如何解决这个问题,所以任何提示都将非常感激.我尝试过的事情:用作曲家安装.用.zip安装.
遵循以下步骤:http://docs.aws.amazon.com/aws-sdk-php/guide/latest/installation.html
aws-sdk ×10
node.js ×5
amazon-s3 ×4
javascript ×3
aws-lambda ×2
amazon-sns ×1
email ×1
java ×1
lambda ×1
php ×1
reactjs ×1
rest ×1
ruby ×1
sinon ×1