从 AWS Lambda JS SDK 访问 EC2 资源

Access EC2 resources from AWS Lambda JS SDK

我正在编写一个函数,需要向 EC2 发出一些请求以创建和删除快照。但是,目前 Lambda 中没有直接使用 EC2 资源发出请求的功能。我正在尝试使用 Class: AWS.TemporaryCredentials 但有一条通知写道:

Note: In order to create temporary credentials, you first need to have "master" credentials configured in AWS.Config.credentials. These master credentials are necessary to retrieve the temporary credentials, as well as refresh the credentials when they expire.

所以我不确定如何存储凭证,因为这个 Lambda 只是一个函数。

为了让您的 Lambda 函数发出 EC2 请求,您必须创建一个具有必要权限的 IAM 角色,然后将该角色与您的 IAM 函数相关联。 AWS Lambda CreateFunction API 请求有一个名为 Role 的必需参数,它是您创建的新角色的 ARN。这样,每次您的 Lambda 函数 运行 Lambda 都会创建临时 AWS 凭证供其使用,该凭证具有角色中定义的权限。