CloudFormation 是一种用于定义和部署 AWS 资源的模板语言和服务。胶水作业(Glue Job)是 AWS Glue 服务中用于数据处理和转换的任务。要使用 CloudFormation 启动胶水作业,你需要创建一个 CloudFormation 模板,并在其中定义胶水作业资源。
以下是一个简单的 CloudFormation 模板示例,用于启动一个胶水作业:
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS CloudFormation template to create a Glue Job
Resources:
GlueJob:
Type: AWS::Glue::Job
Properties:
Name: MyGlueJob
Role: !GetAtt GlueJobRole.Arn
Command:
Name: glueetl
ScriptLocation: s3://my-bucket/my-script.py
DefaultArguments:
- '--job-bookmark-option': 'job-bookmark-enable'
AllocatedCapacity: 10
Timeout: 60
MaxRetries: 0
GlueJobRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: glue.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: GlueJobExecutionRole
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- glue:CreateJob
- glue:GetJob
- glue:UpdateJob
- glue:DeleteJob
- glue:GetJobRun
- glue:GetJobRuns
- glue:BatchGetPartition
- glue:GetPartition
- glue:GetPartitions
- glue:BatchCreatePartition
- glue:CreatePartition
- glue:DeletePartition
- glue:UpdatePartition
Resource: '*'
AWS::Glue::Job
。AWS::IAM::Role
。GlueJobExecutionRole
策略。ScriptLocation
是否正确,并确保脚本存在于指定的 S3 路径中。通过以上步骤和示例,你可以使用 CloudFormation 模板成功启动和管理 AWS Glue 作业。