この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
先日追加されたAWS GlueのSpark ETL ジョブ「Glue Version 2.0」ですが、既存の「Glue Version 1.0」から「Glue Version 2.0」へのバージョンアップが行えるかについて実際に確認してみました。
参考:[新機能] AWS Glue 「Glue Version 2.0」のSpark ETL ジョブの開始時間が10倍速く、最小の請求時間は1分になりました!
確認内容
今回確認する観点は、以下の点になります。
- バージョンアップが可能か(新規作成のみではないか)
- バージョンアップによりジョブが失敗することはないか
- バージョンアップによりジョブの実行履歴が消えてしまわないか
これらの観点について、下記の3通りの方法について検証します。
- AWSコンソールを用いたバージョンアップ
- CloudFormationを用いたバージョンアップ
- Serverless Frameworkを用いたバージョンアップ
AWS CLI v2やServerless Frameworkの導入方法については本記事では割愛させていただきます。
AWSコンソールを用いたバージョンアップ
まずはAWSコンソールからジョブのプロパティを下記のように入力してジョブを作成します。
指定したIAM RoleはAmazonS3FullAccess
, AWSGlueServiceRole
ポリシーが付与されたものです。
Glue Version 1.0
からGlue Version 2.0
へのバージョンアップを検証するため、Glue VersionはSpark 2.4, Python 3(Glue Version 1.0)
を選択します。
検証ではスクリプトの処理内容については検証しないため、ユーザが作成する新しいスクリプトを選択し、スクリプトのパスと一時ディレクトリに適当なS3のパスを入力します。
ジョブを作成したらスクリプトを保存します。
今回はバージョンアップが目的のためスクリプト内容は最低限のものとします。
import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
from awsglue.context import GlueContext
from awsglue.job import Job
def main():
print("Glue Job Start.")
glueContext = GlueContext(SparkContext.getOrCreate())
if __name__ == '__main__':
main()
上記のスクリプトを保存しジョブの実行を行います。
ジョブの実行ステータスがSucceededであることを確認したらバージョンアップを行います。
ジョブの編集ダイアログからSpark 2.4, Python 3 with improved job startup times (Glue Version 2.0)
を選択してバージョンアップを行い、再度ジョブの実行を行います。
ジョブ完了まで待機し、実行履歴を確認したところバージョン1.0、2.0の両者ともに表示されSucceededであることが確認できました。
AWSコンソールから既存の「Glue Version 1.0」ジョブを「Glue Version 2.0」へバージョンアップさせることは問題なく可能なようです。
CloudFormationを用いたバージョンアップ
次にCloudFormationでのバージョンアップが可能であるかについて確認します。
下記のようなテンプレートを用意します。
指定できる値については公式ドキュメントを参照してください。
ScriptLocationには先ほどAWSコンソールの手順で保存したスクリプトのパスを入力しましょう。
AWSTemplateFormatVersion: 2010-09-09
Description: Glue job ver 1.0
Resources:
GlueSampleJob:
Type: AWS::Glue::Job
Properties:
Command:
Name: glueetl
PythonVersion: 3
ScriptLocation: "s3://xxxxxxx/xxx/xx"
ExecutionProperty:
MaxConcurrentRuns: 50
GlueVersion: '1.0'
MaxCapacity: 8
Name: TestJobYokoyamaCF
Role: <指定するIAM RoleのARN>
このテンプレートを用いてCloudFormationでデプロイします。
yokoyama$ aws cloudformation create-stack --stack-name GlueJobStackYokoyama --template-body file://template_ver1.yaml
{
"StackId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxx:stack/GlueJobStackYokoyama/81e87fe0-f3f0-11ea-9af9-0a4c59d332e0"
}
スタックのデプロイが完了したら、AWSコンソール上でジョブの実行を行います。
ジョブの実行ステータスがSucceededであることを確認したら、バージョンアップを行います。
テンプレート内容をVersion 2.0のものに変更します。
AWSTemplateFormatVersion: 2010-09-09
Description: Glue job ver 2.0
Resources:
GlueSampleJob:
Type: AWS::Glue::Job
Properties:
Command:
Name: glueetl
PythonVersion: 3
ScriptLocation: "s3://xxxxxxx/xxx/xx"
ExecutionProperty:
MaxConcurrentRuns: 50
GlueVersion: '2.0'
Name: TestJobYokoyamaCF
NumberOfWorkers: 8
Role: <指定するIAM RoleのARN>
WorkerType: Standard
変更点としては下記になります。
- GlueVersion:2.0
- MaxCapacity:削除
- NumberOfWorkers:8で追加
- WorkerType:Standardで追加
このテンプレートを用いてCloudFormationでスタックを更新します。
yokoyama$ aws cloudformation update-stack --stack-name GlueJobStackYokoyama --template-body file://template_ver2.yaml
{
"StackId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxx:stack/GlueJobStackYokoyama/81e87fe0-f3f0-11ea-9af9-0a4c59d332e0"
}
ジョブの更新が完了したら、AWSコンソール上でジョブの実行を行います。
ジョブ完了まで待機し、実行履歴を確認したところバージョン1.0、2.0の両者ともに表示されSucceededであることが確認できました。
CloudFormationを用いて既存の「Glue Version 1.0」ジョブを「Glue Version 2.0」へバージョンアップさせることは問題なく可能なようです。
Serverless Frameworkを用いたバージョンアップ
次にServerless Frameworkでのバージョンアップが可能であるかについて確認します。
下記のようなテンプレートを用意します。
リソースの指定はCloudFormationで指定したものと同様です。
service: glue-job-yokoyama
frameworkVersion: '1'
provider:
name: aws
runtime: python3.8
region: ap-northeast-1
resources:
Resources:
GlueSampleJob:
Type: AWS::Glue::Job
Properties:
Command:
Name: glueetl
PythonVersion: 3
ScriptLocation: "s3://xxxxxxx/xxx/xx"
ExecutionProperty:
MaxConcurrentRuns: 50
GlueVersion: '1.0'
MaxCapacity: 8
Name: TestJobYokoyamaSL
Role: <指定するIAM RoleのARN>
Serverless Frameworkでデプロイしてみましょう。
yokoyama$ serverless deploy --config serverless_ver1.yml
Serverless: Packaging service...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
........
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
......
Serverless: Stack update finished...
Service Information
service: glue-job-yokoyama
stage: dev
region: ap-northeast-1
stack: glue-job-yokoyama-dev
resources: 3
api keys:
None
endpoints:
None
functions:
None
layers:
None
サービスのデプロイが完了したら、AWSコンソール上でジョブの実行を行います。
ジョブの実行ステータスがSucceededであることを確認したら、バージョンアップを行います。
テンプレート内容をVersion 2.0のものに変更します。
service: glue-job-yokoyama
frameworkVersion: '1'
provider:
name: aws
runtime: python3.8
region: ap-northeast-1
resources:
Resources:
GlueSampleJob:
Type: AWS::Glue::Job
Properties:
Command:
Name: glueetl
PythonVersion: 3
ScriptLocation: "s3://xxxxxxx/xxx/xx"
ExecutionProperty:
MaxConcurrentRuns: 50
GlueVersion: '2.0'
NumberOfWorkers: 8
WorkerType: Standard
Name: TestJobYokoyamaSL
Role: <指定するIAM RoleのARN>
リソースの指定方法についてはCloudFormationと同様になります。
このテンプレートを用いてServerless Frameworkでサービスを更新します。
yokoyama$ serverless deploy --config serverless_ver2.yml
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.....
Serverless: Stack update finished...
Service Information
service: glue-job-yokoyama
stage: dev
region: ap-northeast-1
stack: glue-job-yokoyama-dev
resources: 3
api keys:
None
endpoints:
None
functions:
None
layers:
None
サービスの更新が完了したら、AWSコンソール上でジョブの実行を行います。 ジョブ完了まで待機し、実行履歴を確認したところバージョン1.0、2.0の両者ともに表示されSucceededであることが確認できました。
Serverless Frameworkを用いて既存の「Glue Version 1.0」ジョブを「Glue Version 2.0」へバージョンアップさせることは問題なく可能なようです。
最後に
AWSコンソール、CloudFormation、Serverless FrameworkのいずれもAWS Glueの既存ジョブを「Glue Version 1.0」から「Glue Version 2.0」へのバージョンアップすることは可能でした。
しかし「Glue Version 2.0」ジョブの実行ステータスはSucceededとなりましたが、今回の検証ではClass path contains multiple SLF4J bindings.
というLogger関連のエラーログが出力されていました。
Glue Sparkジョブのログ監視設定等を行っている場合には、影響の確認が必要になりそうです。
注意として、今回検証に利用したコードはロジックのない簡単なもののため実稼働しているコードをバージョンアップする場合はきちんとテスト等を行ってください。
以上になります。この記事がどなたかの助けになれば幸いです。