我正在尝试S3通过aws-sdk我的 lambda 函数进行访问。
import S3 from 'aws-sdk/clients/s3';
const s3 = new S3();
const { Contents: results } = await s3.listObjects({ Bucket: process.env.DOCUMENTS_BUCKET_NAME! }).promise()
Run Code Online (Sandbox Code Playgroud)
我也使用命令成功部署了它cdk deploy。但是当我测试时,我收到以下错误
2022-11-23T15:53:40.891Z undefined ERROR Uncaught Exception
{
"errorType": "Runtime.ImportModuleError",
"errorMessage": "Error: Cannot find module 'aws-sdk'\nRequire stack:\n- /var/task/index.js\n- /var/runtime/index.mjs",
"stack": [
"Runtime.ImportModuleError: Error: Cannot find module 'aws-sdk'",
"Require stack:",
"- /var/task/index.js",
"- /var/runtime/index.mjs",
" at _loadUserApp (file:///var/runtime/index.mjs:1000:17)",
" at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:21)",
" at async start (file:///var/runtime/index.mjs:1200:23)",
" at async file:///var/runtime/index.mjs:1206:1" …Run Code Online (Sandbox Code Playgroud) 希望“事件”这个词在拉库兰没有用词不当。据我了解,Supplies相当于 NodeJS 等其他编程语言中“事件”的 Raku 版本。emit在 NodeJS 中,您可以注册不同的事件,这些事件可以通过 的第一个参数专门指定。在 Raku 中可以做到这一点吗?
const EventEmitter = require('events');
const eventEmitter = new EventEmitter();
eventEmitter.on('start', () => {
console.log('started');
});
eventEmitter.on('end', (value) => {
console.log(`ended ${value}` );
});
eventEmitter.emit('start');
eventEmitter.emit('end', 23);
Run Code Online (Sandbox Code Playgroud)
我正在阅读《很好的用品:处理异步数据的语法救济》(我还没有完成),我看到 jnthn 实现了订阅机制subscribe,send所以我想知道这是否是解决问题的方法。
我想限制对 S3 存储桶中单个文件夹的访问,并且我已经为其编写了 IAM。但是我仍然无法将文件上传/同步到此文件夹。这里bucket是存储桶名称,folder也是我想要授予访问权限的文件夹。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowUserToSeeBucketListInTheConsole",
"Action": [
"s3:ListAllMyBuckets",
"s3:GetBucketLocation"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::*"
]
},
{
"Sid": "AllowRootAndHomeListingOfBucket",
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::bucket"
],
"Condition": {
"StringEquals": {
"s3:prefix": [
""
],
"s3:delimiter": [
"/"
]
}
}
},
{
"Sid": "AllowListingOfUserFolder",
"Action": [
"s3:ListBucket",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:HeadObject"
],
"Effect": "Allow",
"Resource": [
"arn:aws:s3:::bucket"
],
"Condition": {
"StringLike": {
"s3:prefix": [ …Run Code Online (Sandbox Code Playgroud) 我正在实现一个简单的链表并表示没有下一个节点的事实,我使用了 value Nil。问题是,当分配给容器时,Nil将尝试将容器恢复为其默认值,这意味着我需要使用容器的默认值或Any确定是否已到达链表的末尾。但是,我仍然想使用Nil(如果只是为了它的明确意图)并且没有其他值来测试代码中下一个节点的不存在(例如,until $current === Any, last if $current-node === Any;)。对于某些情况:
class Node {
has $.data is rw is required;
has $.next is rw = Nil;
}
class UnorderedList {
has $!head = Nil;
method add(\item --> Nil) {
my $temp = Node.new: data => item;
$temp.next = $!head;
$!head = $temp;
}
method size(--> UInt) {
my $current = $!head;
my UInt $count = 0;
until $current === Any …Run Code Online (Sandbox Code Playgroud) 我的意思是可用于单行。例如这个:
raku -e 'dir(".")==>say()'
Run Code Online (Sandbox Code Playgroud)
打印当前目录中的所有文件和目录。如何更新它以便它递归地工作(没有库和/或用户定义的例程)?还是不可能?
我:recursive在某处看到了提到的标志,但这不起作用:
> raku -e 'dir(".", :recursive)==>say()'
Cannot resolve caller dir(Str:D, :recursive); none of these signatures matches:
(IO(Any) $path, Mu :$test!)
(IO(Any) $path)
(Mu :$test!)
()
in block <unit> at -e line 1
Run Code Online (Sandbox Code Playgroud)
它在缺少 shell 工具(在 Windows 上)或具有不同版本/分支的常用工具的环境中可能很有用。
假设我有以下课程:
class A {
has $.val;
method Str { $!val ~ 'µ' }
}
# Is this the right way of doing it?
multi infix:<~>(A:D $lhs, A:D $rhs) {
('(', $lhs.val, ',', $rhs.val, ')', 'µ').join;
}
Run Code Online (Sandbox Code Playgroud)
如何以与上一类+相同的方式重载某个类的运算符(例如)Str?
我猜这仅适用于在实例对象上调用的方法,并且multi operator-type:<OP>(T $lhs, T $rhs) { }对运算符使用语法是正确的解决方法,但我不确定。
例如,在Python中,以运算符(例如operator.__add__)和运算符(例如+)命名的特殊方法之间似乎存在对应关系。此外,自定义类的任何运算符重载都在该类内部完成。
假设我有以下模块:
module Simple-Mod;
#| Calculate the nth fibonacci number.
multi fib( 0 ) { 1 }
multi fib( 1 ) { 1 }
multi fib( Int $n where * > 1 ) {
fib($n - 2 ) + fib($n - 1);
}
#| Say hello to a person.
sub hello( $person ) { say "Hello, $person!" }
=begin pod
=head1 SYNOPSIS
A really simple module.
=head1 Example
=begin code
use Simple-Mod;
say fib(3); #=> 2
hello("Gina"); #=> Hello, Gina!
=end …Run Code Online (Sandbox Code Playgroud) DateTime当我在序列运算符 ( ) 的两侧使用两个对象时...,Raku 报告说No such method 'succ' for invocant of type 'DateTime'. Did you mean any of these: 'sum', 'utc'?
DateTime.new("2022-03-26") ... DateTime.new("2022-03-28")
Run Code Online (Sandbox Code Playgroud)
然而,当运算符的左侧...是一个Date对象,右侧也是一个DateTime对象时,就会导致无限循环:
.say for Date.new("2022-03-26") ... DateTime.new("2022-03-28");
.say for Date.new("2022-03-26") ... DateTime.new("2022-03-18");
Run Code Online (Sandbox Code Playgroud)
上述语法有效吗?是否应该报告错误?
作为比较,以下代码运行良好:
.say for Date.new("2022-03-26") .. DateTime.new("2022-03-28")
.say for Date.new("2022-03-26") .. Date.new("2022-03-28")
Run Code Online (Sandbox Code Playgroud)
输出:
2022-03-26
2022-03-27
2022-03-28
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Raku 中使用sodNativeCall,但我不断收到分段错误错误。
#!/usr/bin/env raku
use v6.d;
use NativeCall;
class Image is repr('CStruct') {
has int32 $.h;
has int32 $.w;
has int32 $.c;
has Pointer[num32] $.data;
}
sub sod_make_random_image(
int32 $h,
int32 $w,
int32 $c,
) returns Image is native("$*CWD/sod") { * }
sub sod_img_save_as_png(
Image $img,
Str $filename,
--> uint8 ) is native("$*CWD/sod") { * }
my $img = sod_make_random_image(100, 100, 3);
say sod_img_save_as_png($img, "test.png");
Run Code Online (Sandbox Code Playgroud)
我编译了运行的库gcc -shared -Wall -fPIC -o libsod.so sod.c -std=c99。rakudo-gdb-m …
我正在阅读《操作系统:三个简单的部分》,我了解彼得森的算法是一种同步机制,可以在进程/线程之间提供互斥,但是我不清楚该算法是否是任何编程语言中并发结构实现的基础。举个例子,这个 Raku 代码片段及其关键部分,即 ,$counter += 1通过使用Lock结构进行保护:
my UInt:D $counter = 0;
my Lock:D $lock = Lock.new;
my Thread:D $t0 = Thread.start({
for 1..1000 {
$lock.protect({ $counter += 1 });
}
});
my Thread:D $t1 = Thread.start({
for 1..1000 {
$lock.protect({ $counter += 1 });
}
});
$t0.finish;
$t1.finish;
say "Counter: $counter";
Run Code Online (Sandbox Code Playgroud)
假设我了解 Peterson 算法的缺点/缺点,我可以Lock用 Peterson 算法替换 Raku 的算法,并且仍然拥有一个带有受保护关键部分的工作程序吗?
总之,彼得森的算法只是一种教学练习吗?例如,它与互斥锁有什么关系?它是否可以在生产代码中使用(再次假设我知道我在做什么)?
raku ×8
amazon-s3 ×2
perl6 ×2
algorithm ×1
asynchronous ×1
aws-cdk ×1
aws-cli ×1
aws-lambda ×1
concurrency ×1
date ×1
datetime ×1
events ×1
node.js ×1
nodes ×1
promise ×1