Using AWS Glue Python shell job to run Athena query

Using AWS Glue Python shell job to run Athena query

Share Everywhere

Table of contents

phải set up S3 và athena endpoint – nếu dùng Athena endpoint thì sẽ k cần NAT, không cần internet connection!

Note: Có thể sử dụng Glue endpoint thay vì Athena endpoint

Tạo job

  • Chọn Python Shell script editor
  • Chọn Create
  • Click sang Job detail:
    • Điền Name
    • Chọn IAM Role
    • Click mở rộng Advanced properties
    • Chọn Connection đã tạo ở phần Connections
    • Click sang tab Script
    • Dán script vào editor
    • Save
    • Chọn Run để run job

Script để run

import time
import boto3

query = 'SELECT * FROM cloudtrail_logs_aws_cloudtrail_logs_741023408660_05daf6c9 LIMIT 5'
DATABASE = 'default'
output='s3://yen-bucket-demo/'

query = "SELECT * FROM default.tb"
client = boto3.client('athena')
# Execution
response = client.start_query_execution(
    QueryString=query,
    QueryExecutionContext={
        'Database': DATABASE
    },
    ResultConfiguration={
        'OutputLocation': output,
    }
)
print(response)

Cái SG để Glue connect tới S3 hơi đặc biệt chút, nếu không mở all TCP port thì sẽ toang kết nối.  -> phải có ít nhất 1 rule mở all TCP trong SG!

=> Chốt vấn đề ở đây là:

1/ Khi gặp timeout, đầu tiên hãy kiểm tra SG! Nếu đảm bảo SG không sai rồi thì tiếp tục investigate tới endpoint!

2/ Buộc phải tạo S3 endpoint và Athena endpoint cho VPC. Với S3 endpoint, nếu sử dụng dạng Gateway thì phải kiểm tra route table xem đã route đến chưa. Còn Athena endpoint hay S3 endpoint dạng Interface thì không cần route. (Lưu ý: Interface mất phí, còn Gateway thì không)

3/ Nếu đã tạo rồi, vẫn thấy không được thì thử xóa gateway đi tạo lại?!

Bạn thấy bài viết này như thế nào?
1 reaction

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Image CAPTCHA
Enter the characters shown in the image.

Bài viết liên quan

Redshift – xem cluster resize status

Redshift – xem cluster resize status

Tuy là về logic thì cũng không đc thuyết phục lắm, nhưng họ đã làm test và cũng khẳng định như vậy rồi, thì có thể là đặc điểm của redshift này nó thế
MongoDB replica set authentication guide

MongoDB replica set authentication guide

You have to launch at least 3 EC2 instances. Make sure those 3 instances can connect to each other
Sử dụng AWS copilot CLI để đơn giản hóa việc tạo và quản lý ECS cluster

Sử dụng AWS copilot CLI để đơn giản hóa việc tạo và quản lý ECS cluster

AWS Copilot CLI là công cụ có thể tạo ra “production ready containerized applications” một cách nhanh chóng, chỉ cần 1 file Dockerfile thôi, mọi chuyện còn lại có Copilot lo
Hướng dẫn sử dụng đăng nhập với FB, GG Cognito

Hướng dẫn sử dụng đăng nhập với Facebook, Google bằng AWS Cognito

Under Website, enter a sign-in URL for your app client endpoint into Site URL. Your sign-in URL should be in the following
Meetup 11 - Data Streaming on AWS là Meetup đầu tiên của Viet-AWS

Meetup 11 - Data Streaming on AWS là Meetup đầu tiên của Viet-AWS

Đặc biệt cảm ơn tất cả mọi người đã dành thời gian tham gia offline Meetup 11.