在 Elastic Beanstalk 环境中运行 Rails rake 任务

Posted

技术标签:

【中文标题】在 Elastic Beanstalk 环境中运行 Rails rake 任务【英文标题】:Run Rails rake task in Elastic Beanstalk environment 【发布时间】:2016-02-13 01:22:32 【问题描述】:

有谁知道在 Elastic Beanstalk 环境中为 Rails 应用程序运行 rake 任务的最简单方法?

我有一些数据想每隔一段时间重置一次(时间线待定)。我看到其他帖子谈论创建一个 cron 任务,但我现在只想一次性执行该任务。

【问题讨论】:

这能回答你的问题吗? Can you run a rails console or rake command in the elastic beanstalk environment? 【参考方案1】:

您需要登录该框才能运行 rake 任务。 只需运行eb ssh <env-name> 您的应用位于/var/app/current

【讨论】:

哦 - 刚刚看到你找到了答案。我认为“eb ssh”会比普通的 ssh 更好地为您服务。 是的,感谢有关“eb ssh”的提示。我必须做的一件事是在我的 .ssh 目录中创建一个“known_hosts”文件夹并将我的 .pem 密钥的副本移动到那里以使其工作【参考方案2】:

想出了一个办法。

使用以下说明通过 SSH 连接到您的 EC2 实例: SSH Instructions(我使用了选项 3) 登录后导航到 /var/app/current 目录 运行您的 rake 任务(rake db:migrate 或您尝试运行的任何任务)

【讨论】:

以上是关于在 Elastic Beanstalk 环境中运行 Rails rake 任务的主要内容,如果未能解决你的问题,请参考以下文章

如何在 aws elastic beanstalk 环境实例启动上运行 shell 脚本

Elastic Beanstalk 上的 Docker => 使用环境配置运行终端

在 AWS Linux 2 上运行的 NGINX 配置中访问 Elastic Beanstalk 环境属性

Elastic Beanstalk 环境的 Auto Scaling 组

使用环境变量在 AWS Elastic Beanstalk 上使用 django 运行 celery

如何在 Elastic Beanstalk 环境中运行的乘客独立上启用“ngx_http_realip_module”?