[DigitalOcean] Space
안녕하세요 아빠곰입니다.
오늘은 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이 있다. 저의 경우는 싱가폴인데 아래 와 같이 입력
Encryption password:
Path to GPG program:
Use HTTPS protocol [Yes]: Yes
HTTP Proxy server name:
[ 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
마무리
확인 방법
{'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",
...중략
}
참고: 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