I am trying to create a job with Amazon Glue, using boto3. I'm using STS to connect to the AWS account, as per the following code:
session_name = 'glue_job_creation'
client = boto3.client("sts",region_name="eu-west-1",endpoint_url="https://sts.eu-west-1.amazonaws.com")
response = client.assume_role(RoleArn=arn , RoleSessionName=session_name)
temp_credentials = response["Credentials"]
glue = boto3.client(service_name='glue', region_name='eu-west-1',
endpoint_url='https://glue.eu-west-1.amazonaws.com',
aws_access_key_id=temp_credentials["AccessKeyId"],
aws_secret_access_key=temp_credentials["SecretAccessKey"],
aws_session_token=temp_credentials["SessionToken"])
def list_glue_jobs():
response = glue.list_jobs()
print(response)
def create_glue_job():
print('creating new glue job...')
print(response)
myJob = glue.create_job(Name='sample', Role=JobRole,
Command={'Name': 'glueetl',
'ScriptLocation': script_location})
myNewJobRun = glue.start_job_run(JobName=myJob['Name'])
return myNewJobRun
The list_job
function works alright, but the create_job
doesn't work. I get the following error:
botocore.errorfactory.AccessDeniedException: An error occurred (AccessDeniedException) when calling the CreateJob operation: User: arn:aws:sts::xxxxxxxxxxxx:assumed-role/assumed-role-name/session-name is not authorized to perform: iam:PassRole on resource: arn:aws:iam::xxxxxxxxx:role/assumed-role because no identity-based policy allows the iam:PassRole action
I do not understand why the session-name
is appended to the User ARN in this case. Also, is the solution to this simply to create an IAM role with the session name appended to the role name like assumed-role/role-name
, or is there something I am missing?