如何在无服务器框架中将AWS账户ID作为自定义变量?

bco*_*a12 5 amazon-web-services serverless-framework

在无服务器框架中,我想将部署存储桶设置为

<project_name>-<stage>-<account_id>
Run Code Online (Sandbox Code Playgroud)

我可以使用自定义变量来获得舞台,例如:

custom:
    stage: ${opt:stage, self:provider.stage}
Run Code Online (Sandbox Code Playgroud)

但是我如何获得aws帐户ID?我已经尝试使用serverless-pseudo-parameters,如下所示,但没有成功。

custom:
    account_id: #{AWS::AccountId}
plugins:
  - serverless-pseudo-parameters
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我将帐户ID设置为自定义变量吗?

fil*_*tto 9

根据文档,要获取帐户 ID,您可以使用外部 js 文件:

// myCustomFile.js
module.exports.getAccountId = async (context) => {
    return context.providers.aws.getAccountId();
};
Run Code Online (Sandbox Code Playgroud)

.

# serverless.yml
service: new-service
provider: aws
custom:
  accountId: ${file(../myCustomFile.js):getAccountId}
Run Code Online (Sandbox Code Playgroud)