GPG 키를 통해 서명시 “gpg에서 데이터를 서명하는데 실패했습니다.”가 나오는 문제에 대한 해결법


환경

  • Git


문제

  • gpg 키를 사용해 git commit을 작성하는데 아래와 같은 이슈 발생
error: gpg에서 데이터를 서명하는데 실패했습니다.
fatal: 커밋 오브젝트를 쓰는데 실패했습니다


해결법

  • 검색해보니 아래 명령어를 사용하면 비밀번호 입력창이 나오고 문제 해결
  • gpg 키를 통한 서명시 비밀번호가 필요한데 해당 방법이 없어서 발생한 이슈로 추정
    • 해당 gpg 키는 초기설정시 비밀번호가 설정된 상태
export GPG_TTY=$(tty)


참고자료

Post about solving issue which appears “gpg failed to sign the data” when sign with GPG key


Environment and Prerequisite

  • Git


Issue

  • There was an issue when make git commit with gpg key
error: gpg failed to sign the data
fatal: failed to write commit object


Solution

  • By searching on web, found that using below command makes to appear password input box and issue solved
  • It seems like there are no ways to input password when sign with gpg key which needs password
    • That gpg key is set with password in intial setting
export GPG_TTY=$(tty)


Reference

Iterable 객체에서 인덱스와 멤버를 반복문에서 동시에 가져오는 방법에 대한 정리


환경

  • Python


enumerate

enumerate 내장 함수

enumerate(iterable, start=0)
  • 내장 함수로 열거 객체를 돌려줍니다. 함수 매개변수로는 iterable 객체가 들어가야 합니다. Iterable에 대해서는 [Python] Iterable과 Iterator를 참고하시면 됩니다.
  • enumerate(iterable, start=0)iterable의 멤버를 해당 멤버의 인덱스와 함께 튜플 형태로 반환합니다.
  • 반환시 형태는 (인덱스, 멤버)입니다.


enumerate 예제

>>> fruits = ["Apple", "Banana", "Grape", "Mango", "Orange"]
>>> list(enumerate(fruits))
[(0, 'Apple'), (1, 'Banana'), (2, 'Grape'), (3, 'Mango'), (4, 'Orange')]
>>> for pair in enumerate(fruits):
...     print(pair)
...
(0, 'Apple')
(1, 'Banana')
(2, 'Grape')
(3, 'Mango')
(4, 'Orange')
>>> for idx, fruit_name in enumerate(fruits):
...     print(f"{idx} and {fruit_name}")
...
0 and Apple
1 and Banana
2 and Grape
3 and Mango
4 and Orange


참고자료

Post about getting index and member of iterable in iteration one at a time


Environment and Prerequisite

  • Python


enumerate

enumerate built-in function

enumerate(iterable, start=0)
  • It is a built-in function which returns an enumerate object. Iterable object is function parameter. There is reference about iterable in [Python](EN) Iterable and Iterator .
  • enumerate(iterable, start=0) returns iterable’s member and its index as tuple.
  • Its form is (index, member) when it returns.


enumerate example

>>> fruits = ["Apple", "Banana", "Grape", "Mango", "Orange"]
>>> list(enumerate(fruits))
[(0, 'Apple'), (1, 'Banana'), (2, 'Grape'), (3, 'Mango'), (4, 'Orange')]
>>> for pair in enumerate(fruits):
...     print(pair)
...
(0, 'Apple')
(1, 'Banana')
(2, 'Grape')
(3, 'Mango')
(4, 'Orange')
>>> for idx, fruit_name in enumerate(fruits):
...     print(f"{idx} and {fruit_name}")
...
0 and Apple
1 and Banana
2 and Grape
3 and Mango
4 and Orange


Reference

Java에서 DynamoDB 테이블을 S3로 내보내자


환경

  • Java
  • Gradle
  • AWS(DynamoDB, S3, IAM)
  • AWS Java SDK(1.x 또는 2.x)
  • IntelliJ


시작하기 전에

  • 해당 내용은 AWS IAM에서 사용자의 생성, 사용자의 역할 및 권한 부여, 사용자의 키(aws_access_key_id, aws_secret_access_key) 발급에 대해서 알고 있다고 가정한다.
  • 해당 내용은 S3에서 버킷의 개념에 대해 알고 있다고 가정한다.
  • 해당 내용은 DynamoDB에서 테이블이 이미 생성되어 있고 해당 테이블의 PITR이 활성화 되어있다고 가정한다. 이 부분에 관해서는 Amazon S3 로 DynamoDB 데이터 내보내기: 작동 방식을 참고한다.


사전 준비

AWS 설정

사용자 및 Credential 설정

  • AWS IAM에서 사용자는 생성되어 있다고 가정한다.
  • 사용자에 해당하는 credential은 이 코드가 실행되는곳에 이미 설정되어 있다고 가정한다. 관련 내용은 Step 1: Set up for this tutorial를 참고한다.

(옵션) AWS IAM 사용자가 아니라 AWS IAM 역할을 사용하는 경우

  • EC2 인스턴스에 IAM 역할을 부여해서 사용하는것처럼 AWS IAM의 역할을 사용하는 경우 해당 역할의 ARN만 사용해주면 되며 정책의 적용 방법은 아래와 모두 동일하다.
  • 사용자 권한 설정의 IAM 정책을 역할에 연결해주고 해당 역할의 ARN을 대상 S3 버킷 정책 설정에 적용하면 된다.

사용자 권한 설정

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowDynamoDBExportAction",
            "Effect": "Allow",
            "Action": "dynamodb:ExportTableToPointInTime",
            "Resource": "arn:aws:dynamodb:us-east-1:111122223333:table/my-table"
        },
        {
            "Sid": "AllowWriteToDestinationBucket",
            "Effect": "Allow",
            "Action": [
                "s3:AbortMultipartUpload",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::your-bucket/*"
        }
    ]
}

대상 S3 버킷 정책 설정

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ExampleStatement",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::123456789012:user/Dave"
            },
            "Action": [
                "s3:AbortMultipartUpload",
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": "arn:aws:s3:::awsexamplebucket1/*"
        }
    ]
}

IntelliJ 설정

  • build.gradle을 이용해서 SDK를 가져왔으며 각 버전에 해당하는 정보는 아래 코드를 참고한다.


코드

Java SDK 1.x

build.gradle

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.12.42'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

ExportDynamoDbTableToS3.java

import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.model.ExportTableToPointInTimeRequest;

public class ExportDynamoDbTableToS3 {

    public static void main(String[] args) {

        // Please fill out below values
        String tableArn = "";
        String s3Bucket = "";
        String s3Prefix = "";
        String exportFormat = "";
        String s3BucketOwner = "";

        AmazonDynamoDB amazonDynamoDB = AmazonDynamoDBClientBuilder.defaultClient();
        ExportTableToPointInTimeRequest exportTableToPointInTimeRequest = new ExportTableToPointInTimeRequest();

        exportTableToPointInTimeRequest.setTableArn(tableArn);
        exportTableToPointInTimeRequest.setS3Bucket(s3Bucket);
        exportTableToPointInTimeRequest.setS3Prefix(s3Prefix);
        exportTableToPointInTimeRequest.setExportFormat(exportFormat);
        exportTableToPointInTimeRequest.setS3BucketOwner(s3BucketOwner);

        amazonDynamoDB.exportTableToPointInTime(exportTableToPointInTimeRequest);

    }
}

Java SDK 2.x

build.gradle

plugins {
    id 'java'
}

group 'org.example'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation platform('software.amazon.awssdk:bom:2.17.14')
    implementation 'software.amazon.awssdk:dynamodb'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

ExportDynamoDbTableToS3.java

import software.amazon.awssdk.services.dynamodb.model.ExportTableToPointInTimeRequest;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;

public class ExportDynamoDbTableToS3 {

    public static void main(String[] args) {

        // Please fill out below values
        String tableArn = "";
        String s3Bucket = "";
        String s3Prefix = "";
        String exportFormat = "";
        String s3BucketOwner = "";

        DynamoDbClient dynamoDbClient = DynamoDbClient.builder().build();
        ExportTableToPointInTimeRequest exportTableToPointInTimeRequest = ExportTableToPointInTimeRequest
                .builder()
                .tableArn(tableArn)
                .s3Bucket(s3Bucket)
                .s3Prefix(s3Prefix)
                .exportFormat(exportFormat)
                .s3BucketOwner(s3BucketOwner)
                .build();

        dynamoDbClient.exportTableToPointInTime(exportTableToPointInTimeRequest);
    }
}


결과

DynamoDB

  • AWS ID와 버킷명은 가렸습니다.

S3


GitHub


참고자료