주섬주섬 개발일지

AWS DynamoDB 가이드 (with Golang) 본문

Programing/Back-End

AWS DynamoDB 가이드 (with Golang)

zzu__e 2024. 1. 31. 14:24

1. AWS CLI 설치

1) AWS CLI MSI 설치 관리자 실행 명령

$ msiexec.exe /i <https://awscli.amazonaws.com/AWSCLIV2.msi>

2) 설치 확인

$ aws --version

3) 참고 가이드

https://docs.aws.amazon.com/ko_kr/cli/latest/userguide/getting-started-install.html

 

최신 버전의 AWS CLI 설치 또는 업데이트 - AWS Command Line Interface

이전 버전에서 업데이트하는 경우 unzip 명령을 실행하면 기존 파일을 덮어쓸지 묻는 메시지가 표시됩니다. 스크립트 자동화와 같은 경우에 이러한 프롬프트를 건너뛰려면 unzip에 대한 -u 업데이

docs.aws.amazon.com

 

2. AWS CLI 프로필 설정

1) 키 페어 생성

- 엑세스 키 ID, 비밀 엑세스 키 필요

- 보안 정책 증명 - DynamoDB 버전으로 설정

2) 프로필 설정

$ aws configure
----------------------------------------------------------------------
  AWS Access Key ID [None]: ###################
  AWS Secret Access Key [None]: ###################
  Default region name [None]: ap-northeast-1
  Default output format [None]: json
----------------------------------------------------------------------

3) 참고 가이드

Configuration basics

 

Configure the AWS CLI - AWS Command Line Interface

AWS requires that all incoming requests are cryptographically signed. The AWS CLI does this for you. The "signature" includes a date/time stamp. Therefore, you must ensure that your computer's date and time are set correctly. If you don't, and the date/tim

docs.aws.amazon.com

 

3. DynamoDB 테이블 구조 확인

1) cmd로 확인하는 방법

$ aws dynamodb describe-table --table-name [vc_location_0829]
// [] 안에 테이블 이름 입력
--------------------------------------------------------------------------
      {
        "Table": {
        "AttributeDefinitions": [
            {
                "AttributeName": "gameId",
                "AttributeType": "S"
            },
            {
                "AttributeName": "locationId",
                "AttributeType": "S"				       <-- Key Type
            }
        ],
        "TableName": "vc_location_0829",
        "KeySchema": [
            {
                "AttributeName": "locationId",	    <-- Key Name
                "KeyType": "HASH"
            }
        ],
 			...
--------------------------------------------------------------------------

2) 콘솔에서 확인하는 방법

  • 접속 경로
AWS → DynamoDB → 테이블 → 해당 테이블

개요 > 파티션 키와 정렬 키 확인 가능

인덱스 > 인덱스 키 확인 가능

표 항목 탐색 > 테이블 내용 확인 가능

  • 항목 조회 방법
    • SELECT * FROM 테이블 WHERE 파티션 키 = value
  • 쿼리 > 파티션 키의 value 입력

 

4. Golang AWS DynamoDB SDK

1) Input Json

3 테이블 구조에서 확인한 키의 종류와 타입(string/number)에 따라 json 구조 변경 필요

  • S - string, N - number

키의 이름과 값을 입력해야만 조회 가능

  • SELECT * FROM 불가능
  • SELECT * FROM 테이블 WHERE key = value
  • SELECT * FROM 테이블 WHERE key = value AND indexKey = value

 

  • 파티션 키만 존재 시

  • 파티션 키와 인덱스 키 존재 시

2) Golang AWS SDK 예제

Amazon DynamoDB Examples Using the AWS SDK for Go

 

Amazon DynamoDB Examples Using the AWS SDK for Go - AWS SDK for Go (version 1)

Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better.

docs.aws.amazon.com

 

'Programing > Back-End' 카테고리의 다른 글

Git 명령어 모음집  (1) 2024.02.01