공부하기싫어
article thumbnail

프로젝트에서 사용할 레퍼런스이다.

 

이미 존재하는 항목의 속성 값만 수정해줄꺼다

 

python 최신 런타임으로 demo function 을 만들어줬다

테이블도 대충 만들어주고 항목을 생성해줬다

 

lambda function
dynamoDB table

 

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

오늘 날자로 해서 테스트해보면

 

테스트 결과

 

테이블 확인

변경이 잘 된다~