如何在无服务器的函数部分设置Lambda层ARN.ts文件



我试图在serverless.ts中设置我的函数中的层的动态ARN我甚至试图硬编码ARN如下,只得到错误。对于yaml只有许多可用的示例,而对于ts则没有由于

layers: {
calulator: {
path: 'calculator-layer',
name: '${sls:stage}-cal-layer',
compatibleRuntimes: ['nodejs16.x'],
compatibleArchitectures: ['x86_64'],
description: 'A hello lambda layer for reusing calculate function across lambdas',
package: {
include: ['../nodejs/**']
}
}
},
// import the function via paths
functions: {
name: hello,
layers: 'arn:aws:lambda:us-east-1:xxxx:layer:dev-cal-layer:1'
},

以上硬编码ARN的编译错误

Type 'string' has no properties in common with type '{ name?: string | undefined; events?: ({ __schemaWorkaround__: null; } | { schedule: string | { rate: string[]; enabled?: boolean | undefined; name?: string | undefined; description?: string | undefined; input?: string | ... 2 more ... | undefined; inputPath?: string | undefined; inputTransformer?: { ...; } | undefi...'.ts(2559)

我想你可以这样做:

functions: {
name: hello,
layers: {
Ref: 'calculator'
},
},

你可以在这里检查Ref的值到. 据我所知,这将是你正在寻找的ARN。

还有这里的Ref引用

问候!