Python
lambda

Python Lambda Tutorials

  • Make requirements file
#requirements.txt
boto3==1.0.0
  • Install packages
pip install -r requirements.txt -t .
  • Login vào dynamodb
$ cat ~/.aws/config
[default]
region = ap-northeast-1

[profile chalice]
output = text
region = ap-northeast-1
$ cat ~/.aws/credentials
[default]
aws_access_key_id=XXX
aws_secret_access_key=XXX

[chalice]
aws_access_key_id = XXXX
aws_secret_access_key = XXX

Có 2 cách để có thể authen vào trong dynamodb trên aws:

### Cách 1: Truyền trực tiếp access_key vs access_secret
import boto3
from boto3.session import Session

dynamodb = boto3.resource('dynamodb', region_name='us-east-1', aws_access_key_id='XXX', aws_secret_access_key='XXX')
table = dynamodb.Table('test')
print(table.creation_date_time)

### Cách 2: truyền thông qua profile
import boto3
from boto3.session import Session

profile = 'chalice'
session = Session(profile_name=profile)
dynamodb = session.resource('dynamodb', region_name='us-east-1')

table = dynamodb.Table('test')
print(table.creation_date_time)