Work/etc

[DigitalOcean] Space

아빠곰의하루하루 2022. 3. 17. 13:58

안녕하세요 아빠곰입니다. 

오늘은 Digital Ocean의 Space, AWS의 S3와 같은 기능을 하는 Space에 관한 글을 작성해 보고자 합니다. 

 

먼저 Why? 

왜 계속 생소한 Digital Ocean이라는 것을 소개하는가?

 - AWS보다 더 좋아서? No. 

결론적으로 말하면 AWS보다 제공하는 편의 기능은 부족하지만 Performance가 충분히 나오고, 비용이 저렴하기 때문입니다. 

 

사실 우리가 비용이 싸다고 생각했던 부분은 월 5달러 부분보다는 Outbound Transfer 비용이 (구간별 차이가 있지만) 다른 서비스 보다 싸다고 판단이 들었습니다. 

 

이번에 확인한 기능은 Expiration입니다. 

 

Digital Ocean의 경우 AWS와 같이 Lifecycle Policy 적용 화면을 제공하고 있지 않기 때문에 API를 이용해서 Lifecycle을 적용할 밖에 없습니다.

 

https://docs.digitalocean.com/reference/api/spaces-api

 

Spaces API Reference Documentation :: DigitalOcean Documentation

Spaces API Reference Documentation Validated on 1 March 2020 • Posted on 1 March 2020 Welcome to the DigitalOcean Spaces object storage API documentation. Spaces provides a RESTful XML API for programmatically managing the data you store through the use

docs.digitalocean.com

Digital Ocean의 공식문서에서 확인해보면 다음과 같이 Tag로 Lifecycle을 적용하는 기능은 지원하지 않습니다.

하지만 Days나 Date를 설정하여 만료된 Object는 자동으로 지운다고 작성되어 있는 것을 확인 할 수 있습니다. 

(추가적으로 S3의 Versioning기능도 없는 상태입니다 - 2022.3.17일 현재)

 

앞서 말한대로 DO(Digital Ocean 이하 DO로 통일)은 별도의 화면을 제공하고 있지 않기 때문에 API를 이용해야 합니다. 

 

API설정

 

[ s3cmd ]

1. s3cmd설치 (혹은 사이트에서 다운로드 가능, aws cli도 동일한 과정으로 설치)

brew install s3cmd

2. s3cmd 설정 

먼저 Key정보는 DO에서 발급 받은 키 정보 입력, 지역 정보는 DO에서 사용하지 않기 때문에 패스

세번째 Endpoint의 경우 space에 들어가보면 지역 정보 Url이 있다. 저의 경우는 싱가폴인데 아래 와 같이 입력 

sgp1.digitaloceanspaces.com

 

네번째, Bucket 생성시 DNS 정보인데 default 와 Host가 다를 경우 입력 
Encryption password:
Path to GPG program:
다섯번째, 암호화..(GPG 바로 적용되는 것은 아니고 나중에 암호화 적용시에 해도 되기에 전부 패스 
Use HTTPS protocol [Yes]: Yes
HTTP Proxy server name:

 

여섯째,  HTTPS프로토콜 이용 및 Proxy 설정 

 

[ AWS Cli ]

 

조금 더 간단하게 설정이 가능하다. 

 

Lifecycle Rule 설정 

json Type 

{
    "Rules": [
        {
            "ID": "Remove check",
            "Status": "Enabled",
            "Prefix": "test1/2/",
            "Expiration": {
                "Days": 1
            }
        },
        {
            "ID": "Remove hello",
            "Status": "Enabled",
            "Prefix": "test2/{dynamic_path}/",
            "Expiration": {
                "Days": 1
            }
        }
    ]
}

 

XML Type - S3CMD 

<?xml version="1.0" ?>
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
	<Rule>
		<ID>Expiration Test1</ID>
		<Prefix>test1/1/</Prefix>
		<Status>Enabled</Status>
		<Expiration>
			<Days>1</Days>
		</Expiration>
	</Rule>

	<Rule>
		<ID>Expiration Test2</ID>
		<Prefix>test2/{dynamic_path}/</Prefix>
		<Status>Enabled</Status>		
		<Expiration>
			<Days>1</Days>
		</Expiration>
    </Rule>
 
</LifecycleConfiguration>

  policy rule의 경우 위와 같이 작성이 된다.

 

Json과 Xml두가지로 작성한 이유?

 S3cmd의 경우 XML 파일이 동작을 했고, awc cli의 경우 json을 이용할 경우에 동작했다. 파일에 이상이 있을때 테스트를 해서 그런지도 모르겠지만 내경우에는 그러했다. 

다만, 다른 분들께 도움이 되면 해서 위처럼 작성한다. 

여러가지 추측은 있지만 확인되지 않아서 .... 이후에 업데이트 하는게 나을듯하다.  

 

또한 days정보는 1이상의 정수만 가능하다. 0일이나 1.5같은 정보 입력시 오류 발생 

 

실행

s3cmd
s3cmd setlifecycle ./lifecycle.xml s3://test-expire -d 
s3cmd getlifecycle s3://test-expire

 s3cmd setlifecycle [File] s3://[bucket name] 명령으로 실행하고 

 s3cmd getlifecycle s3://[bucket name] 로 적용된 라이프 사이클을 확인할 수 있다. 

 

주의 :  이때 Invalid Parameter의 경우 policy파일에 오류가 있을 경우다. 

           절대 친절하지 않아서 화가 났던 부분이다.

           -d를 붙인 것도 디버깅을 위해서  

 AWC Cli
aws s3api put-bucket-lifecycle-configuration --bucket test-expire --endpoint https://sgp1.digitaloceanspaces.com --lifecycle-configuration file://lifecycle.xml
aws s3api get-bucket-lifecycle-configuration --bucket test-expire --endpoint https://sgp1.digitaloceanspaces.com
aws s3api put-bucket-lifecycle-configuration --bucket [버킷명] --endpoint [End Point] --lifecycle-configuration file://[FILE]

aws s3api get-bucket-lifecycle-configuration --bucket [버킷명] --endpoint [End Point]
 
 
 

마무리 

이렇게 적용을 하면 Web에서는 확인이 불가능하다. 따라서 Object 정보를 조회하면 적용 여부를 확인 할 수 있다. 나의 경우에는 cli를 이용하지 않고 python sdk를 (boto)를 이용해서 확인했다. 
 

확인 방법 

Get Object의 Header 정보를 살펴 본다 
 
아래 내용을 보면 expiration 일자가 들어가고 적용한 rule-id를 확인한다. 
 
적용했던 Expiration Test1 이 있는 것을 확인!
{'ContentType': 'image/png', 'Metadata': {}, 'Body': <botocore.response.StreamingBody object at 0x10440bf10>}
    "ResponseMetadata": {
        "RequestId": "tx0000094fb11158a535512-00665da954-3c730491-sgp1b",
        "HostId": "",
        "HTTPStatusCode": 200,
        "HTTPHeaders": {
            "content-length": "25527",
            "accept-ranges": "bytes",
            "last-modified": "Mon, 03 Jun 2024 10:56:01 GMT",
            "x-amz-expiration": "expiry-date=\"Wed, 05 Jun 2024 00:00:00 GMT\", rule-id=\"Expiration Test1\"",
            "x-rgw-object-type": "Normal",
            "etag": "\"1cd2bc53600426698fd21a99ca5a24f9\"",
            "x-amz-request-id": "tx0000094fb11158a535512-00665da954-3c730491-sgp1b",
            "content-type": "image/png",
            "date": "Mon, 03 Jun 2024 11:30:28 GMT",
            "vary": "Origin, Access-Control-Request-Headers, Access-Control-Request-Method",
            "strict-transport-security": "max-age=15552000; includeSubDomains; preload",
            "x-envoy-upstream-healthchecked-cluster": ""
        },
        "RetryAttempts": 0
    },
    "AcceptRanges": "bytes",
    "Expiration": "expiry-date=\"Wed, 05 Jun 2024 00:00:00 GMT\", rule-id=\"Expiration Test1\"",
    "LastModified": "2024-06-03T10:56:01+00:00",
    "ContentLength": 25527,
    "ETag": "\"1cd2bc53600426698fd21a99ca5a24f9\"",
    "ContentType": "image/png",
    ...중략
}
 
 
공식문서에 나와 있는 자동으로 즉시 삭제된다는...옵션은 사실 정상 동작하지는 않았다. 
 
하루 정도 더 뒤에 삭제 되는 것으로 보아서 실시간 보다는 배치로 삭제 하는 것이 아닌가 하는 생각이 들었다.
 
CS로 문의 한 내용도 ...크게 만족스럽지는 않았다. 
 
다만 조금 더 기다린 이후에 분명 Expiry data가 삭제는 된다는 점!
 
 
 
그래서 결론은 S3에 revision을 이용할 정도로 중요한 Object를 사용한다면... DO의 사용은 글쎄.....
 
하지만 Temp성 Object를 이용할 경우에는 낮은 비용으로 한번쯤 사용해 보는게 어떨지... 하는 생각이 든다. 
 
음... 개발자로써는 추천하고 싶지 않지만, 비용이 부족한 곳이라면 고려해볼만한 선택지 라고 생각든다. 
 

 

 

참고: https://docs.digitalocean.com/reference/api/spaces-api/

 

Spaces API Reference Documentation :: DigitalOcean Documentation

Spaces API Reference Documentation Validated on 1 March 2020 • Posted on 1 March 2020 Welcome to the DigitalOcean Spaces object storage API documentation. Spaces provides a RESTful XML API for programmatically managing the data you store through the use

docs.digitalocean.com

https://docs.digitalocean.com/products/spaces/resources/s3cmd/

 

Setting Up s3cmd 2.x with DigitalOcean Spaces :: DigitalOcean Documentation

Setting Up s3cmd 2.x with DigitalOcean Spaces Validated on 19 April 2019 • Posted on 19 April 2019 Spaces is an S3-compatible object storage service that lets you store and serve large amounts of data. Each Space is a bucket for you to store and serve fi

docs.digitalocean.com