在 SAM 模板 (CF Stack) YAML 中引用 AWS Lambda 的角色



我有一个AWS SAM模板定义了一个JavaScript Lambda:

Resources:
notesFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Zip
CodeUri: notes/
Handler: app.lambdaHandler
Runtime: nodejs18.x
Policies:
- AmazonDynamoDBFullAccess
Architectures:
- x86_64
Events:
Fetchnotes:
Type: Api
Properties:
Path: /notes
Method: get
Givenotes:
Type: Api
Properties:
Path: /notes
Method: post
Users:
Type: Api
Properties:
Path: /notes/users
Method: get
Metadata:
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: "es2020"
Sourcemap: true
EntryPoints:
- app.ts

稍后在模板中,我试图引用这个Lambda的角色(示例:Role: !Ref <MyLambdaRole>),但不确定如何做到这一点,因为该角色是在部署SAM模板(CloudFormation堆栈)时动态创建的。知道怎么做吗?

如果您没有在AWS::Serverless::Function定义中提供角色,SAM将创建一个逻辑ID为<function‑LogicalId>Role的角色。

在您的情况下,这将是!Ref notesFunctionRole

相关内容

最新更新