2020년 2월 27일 목요일

PyCharm boto3 autocomplete

1. Install mypy
$ pip install -U mypy

2. Install PyCharm mypy plugin
- Plugins > Marketplace > Mypy

3. Set path to mypy in mypy plugin settings
- Preferences > Mypy > Path (And Test)

4. Install boto3-stubs with boto3 services you use
$ python -m pip install 'boto3-stubs[s3,athena]'



참고 :
https://pypi.org/project/boto3-stubs/#installation

2020년 2월 26일 수요일

Serverless Lambda Environment Variables

# serverless.yml
service: service-name
provider:
  name: aws
  environment:
    FOO: bar

functions:
  hello:
    handler: handler.hello
    FOO2: bar2

# Python handler

import os
...

FOO = os.environ['FOO'])
...


참고 :
https://serverless.com/framework/docs/providers/aws/guide/functions#environment-variables

2020년 2월 5일 수요일

DataGrip Athena 연동

1. Athena JDBC Driver 다운로드

- https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html


2. Driver 추가

- [+] 아이콘 > Driver


1). Genaral 탭

- Name : ex) AWS Athena
- Driver files : [+] 아이콘 > Custom JARs... > 다운로드 받은 Athena JDBC Driver 선택
- Class : com.simba.athena.jdbc.Driver
- URL templates :
# AWS profile 사용시
jdbc:awsathena://AwsRegion=[{host::ap-northeast-2}][\?<;,{:identifier}={:param}>]
# Key, Secret 사용시
jdbc:awsathena://AwsRegion=[{host::ap-northeast-2}][\?<;,UID={user:param},PWD={password:param},{:identifier}={:param}>]

2). Advanced 탭

- S3OutputLocation : s3://쿼리-output-버킷명/
- Workgroup : primary

# AWS profile 사용시 필요
- AwsCredentialsProviderClass : com.simba.athena.amazonaws.auth.DefaultAWSCredentialsProviderChain


3. Data Source 추가

- [+] 아이콘> Data Source > AWS Athena
- Name : 원하는 이름

# AWS profile 사용시
- Host (AWS region) 확인 후 Test Connection

# Key, Secret 사용시
- Host : AWS region
- User : AWS Access Key Id
- Password : AWS Secret Access Key
> Test Connection