AWS Elastic Beanstalk の Ruby on Rails アプリケーションの更新 - AWS SDK for Ruby

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS Elastic Beanstalk の Ruby on Rails アプリケーションの更新

次の例では、us-west-2 リージョンの Rails アプリケーション MyRailsApp の Ruby を更新します。

注記

正常にスクリプトを実行するには、Rails アプリケーションのルートにいる必要があります。

# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # http://aws.amazon.com/apache2.0/ # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. require 'aws-sdk-elasticbeanstalk' # v2: require 'aws-sdk' Aws.config.update({region: 'us-west-2'}) eb = Aws::ElasticBeanstalk::Client.new s3 = Aws::S3::Client.new app_name = 'MyRailsApp' # Get S3 bucket containing app app_versions = eb.describe_application_versions({ application_name: app_name }) av = app_versions.application_versions[0] bucket = av.source_bundle.s3_bucket s3_key = av.source_bundle.s3_key # Get info on environment envs = eb.describe_environments({ application_name: app_name }) env = envs.environments[0] env_name = env.environment_name # Create new storage location resp = eb.create_storage_location() puts "Created storage location in bucket #{resp.s3_bucket}" s3.list_objects({ prefix: s3_key, bucket: bucket }) # Create ZIP file zip_file_basename = SecureRandom.urlsafe_base64.to_s zip_file_name = zip_file_basename + '.zip' # Call out to OS to produce ZIP file cmd = "git archive --format=zip -o #{zip_file_name} HEAD" %x[ #{cmd} ] # Get ZIP file contents zip_contents = File.read(zip_file_name) key = app_name + "\\" + zip_file_name s3.put_object({ body: zip_contents, bucket: bucket, key: key }) date = Time.new today = date.day.to_s + "/" + date.month.to_s + "/" + date.year.to_s eb.create_application_version({ process: false, application_name: app_name, version_label: zip_file_basename, source_bundle: { s3_bucket: bucket, s3_key: key }, description: "Updated #{today}" }) eb.update_environment({ environment_name: env_name, version_label: zip_file_basename })