feat(medusa-file-s3): Allow all AWS options in config (#2809)
This commit is contained in:
1 parent
4ef0bffff9
commit
79cddc23da
4 files changed
+47
-10
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"medusa-file-s3": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add options for s3 configuration for increased flexibility in configuration
|
||||||
@@ -124,6 +124,33 @@ const plugins = [
|
|||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Add AWS Configurations
|
||||||
|
|
||||||
|
You can pass AWS configurations in the plugin's options under the property `aws_config_object`. This property is an object that accepts [AWS Configurations](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html) as its properties.
|
||||||
|
|
||||||
|
For example, you can pass the `region`, `access_key_id` and `secret_access_key` in `aws_config_object`:
|
||||||
|
|
||||||
|
```jsx title=medusa-config.js
|
||||||
|
const plugins = [
|
||||||
|
//...
|
||||||
|
{
|
||||||
|
resolve: `medusa-file-s3`,
|
||||||
|
options: {
|
||||||
|
s3_url: process.env.S3_URL,
|
||||||
|
bucket: process.env.S3_BUCKET,
|
||||||
|
aws_config_object: {
|
||||||
|
region: process.env.S3_REGION,
|
||||||
|
access_key_id: process.env.S3_ACCESS_KEY_ID,
|
||||||
|
secret_access_key: process.env.S3_SECRET_ACCESS_KEY,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure to define `S3_REGION`, `S3_ACCESS_KEY_ID`, and `S3_SECRET_ACCESS_KEY` in your environment variables first.
|
||||||
|
|
||||||
|
|
||||||
:::caution
|
:::caution
|
||||||
|
|
||||||
If you have multiple storage plugins configured, the last plugin declared in the `medusa-config.js` file will be used.
|
If you have multiple storage plugins configured, the last plugin declared in the `medusa-config.js` file will be used.
|
||||||
|
|||||||
@@ -13,5 +13,8 @@ Learn more about how you can use this plugin in the [documentaion](https://docs.
|
|||||||
region: "eu-west-1"
|
region: "eu-west-1"
|
||||||
access_key_id: "YOUR-ACCESS-KEY",
|
access_key_id: "YOUR-ACCESS-KEY",
|
||||||
secret_access_key: "YOUR-SECRET-KEY",
|
secret_access_key: "YOUR-SECRET-KEY",
|
||||||
|
aws_config_object : {
|
||||||
|
// object for aws config properties
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -14,6 +14,7 @@ class S3Service extends AbstractFileService {
|
|||||||
this.secretAccessKey_ = options.secret_access_key
|
this.secretAccessKey_ = options.secret_access_key
|
||||||
this.region_ = options.region
|
this.region_ = options.region
|
||||||
this.endpoint_ = options.endpoint
|
this.endpoint_ = options.endpoint
|
||||||
|
this.awsConfigObject_ = options.aws_config_object
|
||||||
}
|
}
|
||||||
|
|
||||||
upload(file) {
|
upload(file) {
|
||||||
@@ -122,16 +123,17 @@ class S3Service extends AbstractFileService {
|
|||||||
|
|
||||||
updateAwsConfig(additionalConfiguration = {}) {
|
updateAwsConfig(additionalConfiguration = {}) {
|
||||||
aws.config.setPromisesDependency(null)
|
aws.config.setPromisesDependency(null)
|
||||||
aws.config.update(
|
|
||||||
{
|
const config = {
|
||||||
accessKeyId: this.accessKeyId_,
|
...additionalConfiguration,
|
||||||
secretAccessKey: this.secretAccessKey_,
|
accessKeyId: this.accessKeyId_,
|
||||||
region: this.region_,
|
secretAccessKey: this.secretAccessKey_,
|
||||||
endpoint: this.endpoint_,
|
region: this.region_,
|
||||||
...additionalConfiguration,
|
endpoint: this.endpoint_,
|
||||||
},
|
...this.awsConfigObject_,
|
||||||
true
|
}
|
||||||
)
|
|
||||||
|
aws.config.update(config, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user