在 cloudformation 模板中,我创建了一个 opsworks 堆栈、一个层、一个实例和一个应用程序。该模板通过食谱和脚本的厨师食谱来设置和配置实例。如何从模板自动部署应用程序,而无需手动单击堆栈内的部署?部署后,将执行说明书中定义的 Deloy 配方:
"MyLayer": {
"Type": "AWS::OpsWorks::Layer",
"DependsOn" : "OpsWorksServiceRole",
"Properties": {
"AutoAssignElasticIps" : false,
"AutoAssignPublicIps" : true,
"CustomRecipes" : {
"Setup" : ["cassandra::setup","awscli::setup","settings::setup"],
"Deploy": ["imports::deploy"]
},
"CustomSecurityGroupIds" : { "Ref" : "SecurityGroupIds" },
"EnableAutoHealing" : true,
"InstallUpdatesOnBoot": false,
"LifecycleEventConfiguration": {
"ShutdownEventConfiguration": {
"DelayUntilElbConnectionsDrained": false,
"ExecutionTimeout": 120 }
},
"Name": "script-node",
"Shortname" : "node",
"StackId": { "Ref": "MyStack" },
"Type": "custom",
"UseEbsOptimizedInstances": true,
"VolumeConfigurations": [ {
"Iops": 10000,
"MountPoint": "/dev/sda1",
"NumberOfDisks": 1,
"Size": 20,
"VolumeType": "gp2"
}]
}
}
有什么想法吗? 谢谢。
最佳答案
CreateDeployment
API 调用会生成一个一次性事件,该事件会在 OpsWorks 堆栈中执行 Deploy
操作。我认为没有任何官方 CloudFormation 资源直接映射到此,但以下是有关如何在 CloudFormation 模板上下文中调用它的一些想法:
- 写一个Custom Resource创建时调用 CreateDeployment(例如,通过适用于 Node.js 的 AWS 开发工具包)。
- 添加
AWS::CodePipeline::Pipeline
将资源添加到配置为在部署阶段中部署 OpsWorks 应用程序的模板。请参阅Using AWS CodePipeline with AWS OpsWorks Stacks有关此集成的文档。 (虽然它是一个额外的服务 + 复杂性层,但我认为 CodePipeline 无论如何都是一个更好的抽象层,用于对应用程序堆栈中的部署操作进行建模。)
关于deployment - 如何通过cloudformation部署opsworks应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41258791/