简介
cfn-execute-change-set
是一个 npm 包,主要用于 AWS CloudFormation 的自动化批量部署和回滚。该工具可以执行 CloudFormation 上构建的更新集,也可以回滚它。
安装
- 在项目中安装
cfn-execute-change-set
:
npm install -g cfn-execute-change-set
- 填写 AWS 账号的 AccessKeyId 和 SecretAccessKey。
aws configure
- 为项目创建配置文件
cfn.config.json
,并按需要填写 AWS 配置及部署信息。具体配置请参考 npm 包官方文档。
使用教程
执行 CloudFormation 更新集
确认 CloudFormation 栈已经创建完成。
使用
cfn-execute-change-set
命令执行更新集。
cfn-execute-change-set execute -n <更新集名称> -s <CloudFormation 栈名称> -p <要更新的参数值>
回滚 CloudFormation 更新集
- 查看 CloudFormation 栈来源的更新集并选择要回滚的更新集。
aws cloudformation describe-change-sets --stack-name <CloudFormation 栈名称>
- 使用
cfn-execute-change-set
命令回滚选定的更新集。
cfn-execute-change-set execute -n <回滚的更新集名称> -s <CloudFormation 栈名称>
示例代码
-- -------------------- ---- ------- -- --------------- -- - ------------ ----------------- ------------- ---------- --------------- ---------------- ------------------- -------------------- ------------------- -------------------------- ------------------ ------------------- ------------------ ------------------------- ------------------------ - ------ ------- - -展开代码
// 示例1 - 执行 CloudFormation 栈更新 cfn-execute-change-set execute -n test-cf-changeset-<时间戳> -s test-cf-stack -p key=value // 示例2 - 回滚 CloudFormation 栈更新 cfn-execute-change-set execute -n test-cf-changeset-<时间戳> -s test-cf-stack
总结
cfn-execute-change-set
是一个非常实用的 npm 包,可以帮助前端开发人员自动化部署和回滚 AWS CloudFormation 构建的更新集。熟练掌握该工具,将会大大提高开发和部署效率。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/99842