Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing ParamValidationError when executing load_file in Glue hooks/operators #16012

Merged
merged 8 commits into from
Aug 10, 2021

Conversation

rahulraina7
Copy link
Contributor

Use of s3Hook load_file is wrong and leads to an error

botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid bucket name "artifacts/glue-scripts/myscript.py": Bucket name must match the regex "^[a-zA-Z0-9.\-_]{1,255}$" or be an ARN matching the regex "^arn:(aws).*:(s3|s3-object-lambda):[a-z\-0-9]+:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-]{1,63}$|^arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63}$"

^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

@boring-cyborg boring-cyborg bot added area:providers provider:amazon-aws AWS/Amazon - related issues labels May 23, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented May 23, 2021

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@rahulraina7
Copy link
Contributor Author

rahulraina7 commented May 24, 2021

I have also updated the glue hook to use IAM arn for its execution role.
As there can be a path associated with a role name, This won't work if there is an actual path present.

Example:

{'Role': {'Path': '/dataplatform/glue/', 'RoleName': 'glue-role', 'RoleId': 'AROAU2X5YFLK4EU5OCRWW', 'Arn': 'arn:aws:iam::****:role/dataplatform/glue/glue-role', 'CreateDate': datetime.datetime(2021, 5, 23, 14, 50, 3, tzinfo=tzutc()), 'AssumeRolePolicyDocument': {'Version': '2012-10-17', 'Statement': [{'Sid': '', 'Effect': 'Allow', 'Principal': {'Service': 'glue.amazonaws.com'}, 'Action': 'sts:AssumeRole'}]}, 'MaxSessionDuration': 3600, 'RoleLastUsed': {'LastUsedDate': datetime.datetime(2021, 5, 24, 6, 1, 50, tzinfo=tzutc()), 'Region': 'ap-southeast-1'}}, 'ResponseMetadata': {'RequestId': '25bffed5-ef5d-41eb-8959-16e75961d896', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': '25bffed5-ef5d-41eb-8959-16e75961d896', 'content-type': 'text/xml', 'content-length': '1005', 'date': 'Mon, 24 May 2021 11:14:04 GMT'}, 'RetryAttempts': 0}}

Its better to use Arn since the underlying API in boto3 supports that

@rahulraina7 rahulraina7 changed the title Fixing s3 hook load_file use in glue operator Fixing Glue hooks/operators May 24, 2021
@potiuk
Copy link
Member

potiuk commented Jun 21, 2021

Is it possible to add some unit tests with mocking for that ?

@github-actions
Copy link

github-actions bot commented Aug 6, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Aug 6, 2021
@rahulraina7
Copy link
Contributor Author

Updated tests. Please review @uranusjr , @o-nikolas

@eladkal eladkal removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Aug 6, 2021
@eladkal
Copy link
Contributor

eladkal commented Aug 6, 2021

@rahulraina7 the glue tests are failing

@rahulraina7
Copy link
Contributor Author

@rahulraina7 the glue tests are failing

Fixed with the latest commit.

@rahulraina7 rahulraina7 closed this Aug 8, 2021
@rahulraina7 rahulraina7 reopened this Aug 8, 2021
@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Aug 10, 2021
@eladkal eladkal changed the title Fixing Glue hooks/operators Fixing ParamValidationError when executing load_file in Glue hooks/operators Aug 10, 2021
@eladkal eladkal merged commit 77c4325 into apache:main Aug 10, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 10, 2021

Awesome work, congrats on your first merged pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers okay to merge It's ok to merge this PR as it does not require more tests provider:amazon-aws AWS/Amazon - related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants