프로젝트에서 사용할 레퍼런스이다.
이미 존재하는 항목의 속성 값만 수정해줄꺼다
python 최신 런타임으로 demo function 을 만들어줬다
테이블도 대충 만들어주고 항목을 생성해줬다
chatGPT 에게 물어봤다
import boto3
def lambda_handler(event, context):
# create a DynamoDB client
dynamodb = boto3.client('dynamodb')
# define the table name and the key of the item to be updated
table_name = 'your-table-name'
item_key = {'id': {'S': 'your-item-key'}}
# define the attribute to be updated and its new value
attribute_name = 'attribute-to-update'
new_value = {'S': 'new-value'}
# update the item with the new attribute value
response = dynamodb.update_item(
TableName=table_name,
Key=item_key,
UpdateExpression='SET #attr = :val',
ExpressionAttributeNames={'#attr': attribute_name},
ExpressionAttributeValues={':val': new_value}
)
return response
인라인 정책을 추가해줬다
코드를 수정해줬다
import boto3
def lambda_handler(event, context):
# create a DynamoDB client
dynamodb = boto3.client('dynamodb')
# define the table name and the key of the item to be updated
table_name = 'table-for-Ethereum-Autotrade'
item_key = {'Env': {'S': 'Dev'}}
# define the attribute to be updated and its new value
attribute_name = 'k-value'
new_value = 0.0402
# update the item with the new attribute value
response = dynamodb.update_item(
TableName=table_name,
Key=item_key,
UpdateExpression='SET #attr = :val',
ExpressionAttributeNames={'#attr': attribute_name},
ExpressionAttributeValues={':val': {'N': str(new_value)}}
)
return response
오늘 날자로 해서 테스트해보면
변경이 잘 된다~
'AWS' 카테고리의 다른 글
[Error] AWS Budget scope 에서 tag가 검색되지 않음 (0) | 2023.10.08 |
---|---|
[TSET] IAM Group 에 역할 및 정책 부여 후 정상 동작 확인 (0) | 2023.10.03 |
[error][cloudformation] Your requested instance type (t3a.small) is not supported (1) | 2023.09.04 |
aws 교과서 수준 블로그 찾음 (0) | 2022.09.16 |
window dos 에서 ssh 사용 AWS EC2 root 접속 (0) | 2022.06.06 |