希望大家注意安全!
我有一个Ruby on Rails应用程序托管在AWS Beanstalk上。我正在使用CloudForm模板,以更新任何堆栈,例如,Ruby版本、Linux平台升级等。
我正在尝试升级。Linux 盒至 2.11.7
和 红宝石 到 2.6.6
然后 弹性搜索 到 7.4
我在CloudFormation YML模板中进行了这些更改,然后我运行了 aws cloudformation update-stack
命令来应用这些更改。
虽然这些更改需要时间,但我不小心点击了 重建环境 因此,所有之前配置的设置,如Web AWS Console中的 SQS, 负载均衡器 等,都被新的设置所取代。
现在,每当我试图执行 update-stack
命令,但却出现以下错误。
2020-06-09 15:25:44 UTC+0530
WARN
Environment health has transitioned from Info to Degraded. Command failed on all instances.
Incorrect application version found on all instances. Expected version "code-pipeline-1591695975198-d485a710a5a5a16e7a099e4e16303ef53c188d54" (deployment 2377). Application update failed 40 seconds ago and took 79 seconds.
2020-06-09 15:25:03 UTC+0530
INFO
The environment was reverted to the previous configuration setting.
2020-06-09 15:24:44 UTC+0530
INFO
Environment health has transitioned from Ok to Info. Application update in progress on 1 instance. 0 out of 1 instance completed (running for 39 seconds).
2020-06-09 15:24:30 UTC+0530
ERROR
During an aborted deployment, some instances may have deployed the new application version.
To ensure all instances are running the same version, re-deploy the appropriate application version.
2020-06-09 15:24:30 UTC+0530
ERROR
Failed to deploy application.
2020-06-09 15:24:30 UTC+0530
ERROR
Unsuccessful command execution on instance id(s) 'i-4d527ff00cb443z11'. Aborting the operation.
2020-06-09 15:24:30 UTC+0530
INFO
Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
2020-06-09 15:24:30 UTC+0530
ERROR
[Instance: i-4d527ff00cb443z11] Command failed on instance. Return code: 18 Output: (TRUNCATED)...g: the running version of Bundler (1.16.0) is older than the version that created the lockfile (1.17.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. Your Ruby version is 2.6.6, but your Gemfile specified 2.6.5. Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
2020-06-09 15:24:19 UTC+0530
INFO
Deploying new version to instance(s).
2020-06-09 15:23:45 UTC+0530
INFO
Updating environment developWeb's configuration settings.
2020-06-09 15:23:36 UTC+0530
INFO
Environment update is starting.
我可以确认我有Ruby-2.6.6的设置。我不知道它从哪里获取了旧版本的Ruby?
有什么办法可以解决这个问题吗?或者强行应用模板变化?
如果能得到任何帮助,我将非常感激。
(更新): 当我尝试从Rails控制台连接到ElasticSearch时,我得到:
Faraday::ConnectionFailed: Failed to open TCP connection to old-elasticsearch-host-name.es.amazonaws.com:80 (Hostname not known: old-elasticsearch-host-name.es.amazonaws.com)
from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/net/http.rb:949:in `rescue in block in connect'
Caused by SocketError: Failed to open TCP connection to old-elasticsearch-host-name.es.amazonaws.com:80 (Hostname not known: old-elasticsearch-host-name.es.amazonaws.com)
from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/net/http.rb:949:in `rescue in block in connect'
Caused by Resolv::ResolvError: no address for old-elasticsearch-host-name.es.amazonaws.com
from /opt/rubies/ruby-2.6.6/lib/ruby/2.6.0/resolv.rb:94:in `getaddress'
elasticsearch 实例的新 URL 是不同的,但它仍然在接收来自 ELASTICSEARCH_HOST
ENV变量。
资料来自我的CF模板。
AWSTemplateFormatVersion: 2010-09-09
Description: CloudFormation template
Conditions:
ProductionCondition: !Equals [!Ref 'AWS::StackName', production]
NotProductionCondition: !Not [!Equals [!Ref 'AWS::StackName', production]]
Parameters:
ElasticSearchInstanceClass:
Description: ElasticSearch instance class
Type: String
Default: t2.small.elasticsearch
Resources:
DeploymentBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub '${AWS::StackName}-deployment'
DeploymentRepository:
Type: AWS::CodeCommit::Repository
Properties:
RepositoryDescription: Deployment Repository
RepositoryName: !Sub '${AWS::StackName}${BaseName}Deployment'
ElasticsearchDomain:
Type: AWS::Elasticsearch::Domain
Properties:
ElasticsearchVersion: 7.4
ElasticsearchClusterConfig:
DedicatedMasterEnabled: true
InstanceCount: 2
ZoneAwarenessEnabled: false
InstanceType: !Ref ElasticSearchInstanceClass
DedicatedMasterType: !Ref ElasticSearchInstanceClass
DedicatedMasterCount: 3
EBSOptions:
EBSEnabled: true
VolumeType: gp2
VolumeSize: 30
SnapshotOptions:
AutomatedSnapshotStartHour: 7
AccessPolicies:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
AWS: '*'
Action: 'es:*'
Resource: '*'
VPCOptions:
SubnetIds:
- subnet-f4ad24de
SecurityGroupIds:
- sg-*
AdvancedOptions:
rest.action.multi.allow_explicit_index: true
RailsApplication:
Type: AWS::ElasticBeanstalk::Application
DependsOn: PostgresDatabase
Properties:
ApplicationName: !Sub '${AWS::StackName}'
Description: !Sub 'Application (${AWS::StackName})'
RailsApplicationVersion:
Type: AWS::ElasticBeanstalk::ApplicationVersion
DependsOn: RailsApplication
Properties:
ApplicationName: !Ref RailsApplication
Description: !Sub 'Application Version (${AWS::StackName})'
SourceBundle:
S3Bucket: !Ref DeploymentBucket
S3Key: code.zip
RailsApplicationTemplate:
Type: AWS::ElasticBeanstalk::ConfigurationTemplate
DependsOn:
- RailsApplicationVersion
- ElasticsearchDomain
Properties:
ApplicationName: !Ref RailsApplication
SolutionStackName: 64bit Amazon Linux 2018.03 v2.11.7 running Ruby 2.6 (Puma)
Description: !Sub 'Configuration Template (${AWS::StackName})'
OptionSettings:
- Namespace: aws:elb:loadbalancer
OptionName: LoadBalancerHTTPSPort
Value: 443
- Namespace: aws:elb:loadbalancer
OptionName: SSLCertificateId
Value: !ImportValue SSLCertificateArn
- Namespace: aws:elb:policies
OptionName: ConnectionDrainingEnabled
Value: true
- Namespace: aws:autoscaling:launchconfiguration
OptionName: IamInstanceProfile
Value: !ImportValue InstanceProfileIdentifier
- Namespace: aws:elasticbeanstalk:application:environment
OptionName: ELASTICSEARCH_HOST
Value: !GetAtt ElasticsearchDomain.DomainEndpoint
- Namespace: aws:elasticbeanstalk:application:environment
OptionName: ELASTICSEARCH_PORT
Value: 80
RailsWebEnvironment:
Type: AWS::ElasticBeanstalk::Environment
DependsOn:
- RailsApplicationTemplate
Properties:
EnvironmentName: !Sub '${AWS::StackName}Web'
ApplicationName: !Ref RailsApplication
Description: !Sub 'Web Environment (${AWS::StackName})'
TemplateName: !Ref RailsApplicationTemplate
VersionLabel: !Ref RailsApplicationVersion
Tier:
Name: WebServer
Type: Standard
RailsWorkerEnvironment:
Type: AWS::ElasticBeanstalk::Environment
DependsOn:
- RailsApplicationTemplate
Properties:
EnvironmentName: !Sub '${AWS::StackName}Worker'
ApplicationName: !Ref RailsApplication
Description: !Sub 'Worker Environment (${AWS::StackName})'
- Namespace: aws:elasticbeanstalk:application:environment
OptionName: AWS_ENV
Value: worker
- Namespace: aws:elasticbeanstalk:application:environment
OptionName: PROCESS_ACTIVE_ELASTIC_JOBS
Value: true
TemplateName: !Ref RailsApplicationTemplate
VersionLabel: !Ref RailsApplicationVersion
Tier:
Name: Worker
Type: SQS/HTTP
ApplicationCodePipeline:
Type: AWS::CodePipeline::Pipeline
DependsOn:
- RailsApplication
- RailsWebEnvironment
- RailsWorkerEnvironment
Properties:
RoleArn: !ImportValue ApplicationRoleArn
Stages:
-
Name: Source
Actions:
-
Name: SourceAction
ActionTypeId:
Category: Source
Owner: AWS
Version: 1
Provider: CodeCommit
OutputArtifacts:
- Name: SourceOutput
Configuration:
BranchName: !Ref RepositoryBranch
RepositoryName: !GetAtt DeploymentRepository.Name
RunOrder: 1
-
Name: Release
Actions:
-
Name: WebReleaseAction
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: ElasticBeanstalk
InputArtifacts:
- Name: SourceOutput
OutputArtifacts: []
Configuration:
ApplicationName: !Ref RailsApplication
EnvironmentName: !Ref RailsWebEnvironment
RunOrder: 1
-
Name: WorkerReleaseAction
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: ElasticBeanstalk
InputArtifacts:
- Name: SourceOutput
OutputArtifacts: []
Configuration:
ApplicationName: !Ref RailsApplication
EnvironmentName: !Ref RailsWorkerEnvironment
RunOrder: 1
ArtifactStore:
Type: S3
Location: !Ref DeploymentBucket
AppliationDomain:
Type: AWS::Route53::RecordSet
Condition: NotProductionCondition
Properties:
HostedZoneId: !ImportValue HostedZoneIdentifier
Comment: Subdomain for this application
Name: !Sub '${AWS::StackName}.host-name.com'
Type: CNAME
TTL: 60
ResourceRecords:
- !Sub '${AWS::StackName}.host-name.com.cdn.cloudflare.net'
这是一个配置问题。
每当我运行 aws update-stack
命令,它是去s3拉取(源代码的)zip代码,在该zip代码的Gemfile中,ruby版本被设置为2.6.5。
所以,我上传了新的源码副本,然后执行update-stack命令,结果成功了。