LoginSignup
0

More than 5 years have passed since last update.

Python Lambda Tutorials

Posted at
  • 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)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0