aws-s3
Instantly deploy and manage your S3 buckets with Serverless Components. Supports acceleration as well as file & directory uploads.
- Install
- Create
- Configure
- Deploy
- Upload
1. Install
$ npm install -g serverless
2. Create
Just create a serverless.yml
file
$ touch serverless.yml
$ touch .env
# .env
AWS_ACCESS_KEY_ID=XXX
AWS_SECRET_ACCESS_KEY=XXX
3. Configure
myBucket:
component: "@serverless/aws-s3"
inputs:
accelerated: false
region: us-east-1
cors:
CORSRules:
- AllowedHeaders:
- "*"
AllowedMethods:
- PUT
- POST
- DELETE
AllowedOrigins:
- http://www.example.com
MaxAgeSeconds: 3000
4. Deploy
$ serverless
5. Upload
If you're using this component programmatically within another component, you could also easily upload files and/or directories to your bucket.
const bucket = await this.load("@serverless/aws-s3");
await bucket({
accelerated: true
});
await bucket.upload({ dir: "./my-files" });
await bucket.upload({ file: "./my-file.txt" });
Cache-control headers can also be set:
await bucket.upload({ dir: "./my-files", cacheControl: "max-age=86400" });
await bucket.upload({ file: "./my-file.txt", cacheControl: "max-age=86400" });
For a full example on how this component could be used, take a look at how the website component is using it.
New to Components?
Checkout the Serverless Components repo for more information.