AWS:我如何从编程中添加IAM角色,并从自动缩放组的启动模板生成的EC2实例中添加IAM角色?

发布于 2025-02-07 23:12:08 字数 938 浏览 2 评论 0原文

我是AWS的新手,我有一个我感到困惑的问题:基本上,我们正在尝试将AWS CloudWatch记录添加到我们的EC2实例中。我能够在登台实例上设置它,并用手动添加IAM角色为CloudWatch添加IAM角色,并运行此文档页面。它使记录工作。然后,我能够为当前活跃的生产EC2实例设置它,还添加了这些规则并通过SSH连接到实例,并从CLI中运行这些命令。

但是,问题在于,每当我们将应用程序重新部署到生产时,都会生成新的生产实例。与舞台不同,该舞台只需将最新更改并运行命令重新启动Docker,并且EC2实例始终运行,并且总是相同的。正在使用启动模板生成生产实例。基本上,我创建了一个登台实例的AMI映像,然后更新启动模板以使用最新的AMI,然后为使用该启动模板的自动尺度组运行实例刷新,该组终止了旧生产EC2实例并创建了新的。 。

但是,与其将这些角色应用并每次手动运行这些命令到新创建的生产EC2实例,我想将其设置为每次生成时都会自动应用它们对于那些新的生产实例和伐木失败。您能告诉我如何将其设置为具有这些角色以及对新生成的生产EC2实例的任何必要配置?

更新:

我尝试将启动模板的“用户数据”更改为这2个选项,但是在(1)情况下,它没有附加任何角色,并且记录失败,并且在(2)案例自动上缩放会失败:

“屏幕截图”

I'm quite new to AWS and I have this issue that I'm confused about: basically we are trying to add AWS Cloudwatch logging to our EC2 instances. I was able to set it up on Staging instance with manually adding IAM Role for Cloudwatch and running those commands described in this documentation page. It made logging work. And then I was able to set it up for our currently active production EC2 instances also adding those rules and running those commands from that article in CLI while connected to the instance via SSH.

The problem, however, is that there are new production instances being generated each time we redeploy our app to production. Unlike the Staging, where simply pull latest changes and run commands to restart Docker, and the EC2 instance is always running and it's always same. Production instances are being generated using a Launch Template. Basically, I create an AMI image of Staging instance, then update the Launch Template to use the latest AMI, then I run instance refresh for the auto-scaling group that uses that Launch Template, which terminates old production EC2 instances and creates the new ones.

But instead of applying those roles and running those commands manually each time to those newly created production EC2 instances I would like to set it up to be applied automatically each time they are being generated since after I do that I no longer see the IAM Roles attached to those new production instances and logging fails. Could you tell me please how could I set it up to have those roles and any necessary configurations applied to the newly generated production EC2 instances?

UPDATE:

I tried changing "User Data" of the Launch Template to those 2 options, however in (1) case it just didn't attach any role and logging failed and in (2) case auto-scaling would fail:

screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文