Cell - Cloud Component
Shared abstractions of the cloud packages: where credentials, region and account come from, and the ObjectStorageService interface that @celljs/oss and @celljs/cos implement.
npm install @celljs/cloudCredentials, region, account
| Component | Default source |
|---|---|
CredentialsProvider | cloud.credentials: { accessKeyId, accessKeySecret, token? } |
RegionProvider | cloud.region |
AccountProvider | cloud.account: { id } |
ClientOptionsProvider | cloud.client: extra options of the vendor client |
cloud:
region: cn-hangzhou
credentials:
accessKeyId: "${env.ACCESS_KEY_ID}"
accessKeySecret: "${env.ACCESS_KEY_SECRET}"Keep credentials in environment variables (${env.X} in cell.yml); configuration is server-only. Bind your own provider (rebind: true) to read them from somewhere else, such as a secrets manager.
Object storage
ObjectStorageService has createBucket, deleteBucket, listBuckets, listObjects, getObject, getStream, putObject, copyObject, deleteObject and headObject, with the same request shapes for every vendor:
import { Autowired, Component } from '@celljs/core';
import { ObjectStorageService } from '@celljs/cloud';
@Component()
export class Uploads {
@Autowired(ObjectStorageService)
protected readonly storage: ObjectStorageService<any>;
save(key: string, body: Buffer) {
return this.storage.putObject({ bucket: 'uploads', key, body });
}
}Install one implementation: @celljs/oss (Alibaba Cloud) or @celljs/cos (Tencent Cloud). getRawCloudService() returns the vendor's own client for anything else.
Deploying an application to a cloud platform does not need this package: see the presets of cell deploy.