S3
The S3 service allows you to read, write, list and delete files from the cloud.
Installation
Follow these instructions to use the S3 module in your project.
Package
Install the package into your project:
pnpm install @juicyllama/app-aws
Api Backend
Import the module into your application, this is not needed if you are using the storage wrapper.
import { AwsS3Module } from '@juicyllama/app-aws'
@Module({
imports: [
AwsS3Module,
],
})
Environment Variables
Regardless weither you use the S3 integration directly or via the storage module you will need to add the following:
- Ensure you have added the AWS config values as per these instructions
- Add these optional S3 specific environment variables:
Environment Variables | Description |
---|---|
AWS_S3_JL_PUBLIC_BUCKET | If you would like to specify a bucket name for public resources |
AWS_S3_JL_PRIVATE_BUCKET | If you would like to specify a bucket name for private resources |
AWS_S3_JL_REGION | If you would like to specify a region for your S3 buckets, note it will fallback to your global AWS_JL_REGION value if this is not provided |
Services
Use the following operations to read, write, list and delete data to S3.
First setup the service:
import { AwsS3Service, AwsS3Bucket, AwsS3Format } from '@juicyllama/app-aws'
@Injectable()
export class AppService {
constructor(@Inject(AwsS3Service) private readonly awsS3Service: AwsS3Service) {}
}
Then you can call the following functions:
Write
Write files to the cloud
async function writeSomething(file: Blob){
const result = await this.awsS3Service.create({
location: '/path/to/save/file/to/file.ext',
permissions: AwsS3Bucket.PRIVATE, // or you can pass the bucket name as a string
format: AwsS3Format.BLOB,
file: file,
})
}
Read
Read file from the cloud
async function readSomething(){
const result = await this.awsS3Service.findOne({
location: '/path/to/read/file/from/file.ext',
permissions: AwsS3Bucket.PRIVATE, // or you can pass the bucket name as a string
format: AwsS3Format.BLOB,
})
}
List
List files from the cloud
async function listFiles(){
const result = await this.awsS3Service.findAll({
location: '/path/to/read/file/from',
permissions: AwsS3Bucket.PRIVATE, // or you can pass the bucket name as a string
})
}
Delete
Delete a file from the cloud
async function readSomething(){
const result = await this.awsS3Service.remove({
location: '/path/to/delete/file/from/file.ext',
permissions: AwsS3Bucket.PRIVATE, // or you can pass the bucket name as a string
})
}
AWS
The AWS app is a nestjs wrapper around the AWS @aws-sdk services. It provides a consistent interface for interacting with AWS within the confines of our framework.
Google Analytics 4
The Google Analytics app is a wrapper around the Google Analytics Data: Node.js Client. It provides a consistent interface for interacting with Google Analytics 4 API within the confines of our framework.