简体   繁体   English

如何告诉我的 Elastic Beanstalk 实例不要进入睡眠状态?

[英]How do I tell my Elastic Beanstalk instance not to go to sleep?

I've setup an Elastic Beanstalk instance on the .NET (Windows/IIS) platform.我已经在 .NET (Windows/IIS) 平台上设置了一个 Elastic Beanstalk 实例。 I've deployed a .NET Core application there that does 2 things:我在那里部署了一个 .NET Core 应用程序,它可以做两件事:

  1. Respond with Hello world!回复 Hello world! when I hit the end point - but I don't care about that.当我到达终点时 - 但我不在乎。
  2. Sets up a listener for RabbitMQ (also hosted in AWS).为 RabbitMQ(也在 AWS 中托管)设置侦听器。 This listener fires off an SMS every time I drop some a message in RabbitMQ.每次我在 RabbitMQ 中发送一条消息时,这个监听器都会触发一条 SMS。

Item 2 works great - I drop off a message and less than a second later I get an SMS message on my phone.第 2 项效果很好 - 我发送了一条消息,不到一秒钟后,我的手机上收到了一条 SMS 消息。

The problem is that AWS puts the application to sleep after a period of inactivity.问题是 AWS 在一段时间不活动后让应用程序进入睡眠状态。 And that causes the RabbitMQ listener to also go to sleep.这会导致 RabbitMQ 侦听器也进入睡眠状态。 This results in undelivered SMS messages.这会导致未送达的 SMS 消息。 Until I wake up the instance by going to the URL assigned to my by Elastic Beanstalk.直到我通过转至 Elastic Beanstalk 分配给我的 URL 唤醒实例。

How do I make my Elastic Beanstalk instance not go to sleep?如何让我的 Elastic Beanstalk 实例不进入睡眠状态? Is there something I can call from C# code to prevent it from doing so?有什么我可以从 C# 代码中调用来阻止它这样做的吗?

Here is what I implemented following this article .这是我在这篇文章之后实现的。

  1. Create a .ebextensions folder at the root of your api/web project.在 api/web 项目的根目录下创建一个 .ebextensions 文件夹。
  2. In this project, any .config file will be used as config for your elastic beanstalk, they will be applied in alphabetical order.在这个项目中,任何 .config 文件都将用作弹性 beantalk 的配置,它们将按字母顺序应用。 So create a file containing the following : (see in the link, the white space is important and I can't seem to get it right here...)所以创建一个包含以下内容的文件:(见链接,空白很重要,我似乎无法在这里找到它......)

    commands: setIdleTimeoutToZero: cwd: "C:\\windows\\system32\\inetsrv" command: "appcmd set apppool /apppool.name:DefaultAppPool /.processModel.idleTimeout:0.00:00:00"命令:setIdleTimeoutToZero:cwd:“C:\\windows\\system32\\inetsrv” 命令:“appcmd set apppool /apppool.name:DefaultAppPool /.processModel.idleTimeout:0.00:00:00”

  3. Make sure the file is always copied to output.确保文件始终复制到输出。

  4. You should be good to go.你应该很高兴去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM