-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Hdworld/storage with existing s3 #7602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
131dd06
add callout for group access precedence
hdworld11 f258bc8
add docs for using storage with own s3 resource
hdworld11 4ee75a2
Merge branch 'main' into hdworld/storage-with-existing-s3
hdworld11 3e834d4
add example separately for Flutter
hdworld11 ffede56
update docs for using with custom s3
hdworld11 f9d31e5
Merge branch 'main' into hdworld/storage-with-existing-s3
hdworld11 6b44e2d
add react-native
hdworld11 5f32c84
Update src/pages/[platform]/build-a-backend/storage/use-with-custom-s…
hdworld11 f448a47
restructure docs for custom s3 bucket
hdworld11 cb248bd
Merge branch 'hdworld/storage-with-existing-s3' of github.com:aws-amp…
hdworld11 128f7ec
fix outputs file name
hdworld11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
src/pages/[platform]/build-a-backend/storage/use-with-custom-s3/index.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; | ||
|
||
export const meta = { | ||
title: 'Use Amplify Storage with any S3 bucket', | ||
description: 'You can use the Amplify Storage APIs against your own S3 bucket in your account.', | ||
platforms: [ | ||
'javascript', | ||
'react', | ||
'react-native', | ||
'angular', | ||
'vue', | ||
'nextjs', | ||
'swift', | ||
'android', | ||
'flutter' | ||
] | ||
}; | ||
|
||
export const getStaticPaths = async () => { | ||
return getCustomStaticPath(meta.platforms); | ||
}; | ||
|
||
export function getStaticProps(context) { | ||
return { | ||
props: { | ||
platform: context.params.platform, | ||
meta | ||
} | ||
}; | ||
} | ||
|
||
With Amplify Storage APIs, you can use your own S3 buckets instead of the Amplify-created ones. | ||
|
||
<Callout> | ||
|
||
**Important:** To utilize the storage APIs with an S3 bucket outside of Amplify, you must have Amplify Auth configured in your project. | ||
ashika112 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
</Callout> | ||
|
||
## Step 1 - Add necessary permissions to the S3 bucket | ||
|
||
For the specific Amazon S3 bucket that you want to use with these APIs, you need to make sure that the associated IAM role has the necessary permissions to read and write data to that bucket. | ||
|
||
To do this, go to **Amazon S3 console** > **Select the S3 bucket** > **Permissions** > **Edit** Bucket Policy. | ||
|
||
 | ||
|
||
The policy will look something like this | ||
|
||
```json | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "Statement1", | ||
"Principal": { "AWS": "arn:aws:iam::<AWS-account-ID>:role/<role-name>" }, | ||
"Effect": "Allow", | ||
"Action": [ | ||
"s3:PutObject", | ||
"s3:GetObject", | ||
"s3:DeleteObject", | ||
"s3:ListBucket" | ||
], | ||
"Resource": [ | ||
"arn:aws:s3:::<bucket-name>/*" | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
Replace `<AWS-account-ID>` with your AWS account ID and `<role-name>` with the IAM role associated with your Amplify Auth setup. Replace `<bucket-name>` with the S3 bucket name. | ||
|
||
You can refer to [Amazon S3's Policies and Permissions documentation](https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-policy-language-overview.html) for more ways to customize access to the bucket. | ||
|
||
## Step 2 - Specify S3 bucket in Amplify's backend config | ||
|
||
Next, use the `addOutput` method from the backend definition object to define a custom s3 bucket by specifying the name and region of the bucket in your **amplify/backend.ts** file. | ||
|
||
<Callout> | ||
|
||
**Important** | ||
|
||
You cannot use both a storage backend configured through Amplify and a custom S3 bucket at the same time. | ||
|
||
If you specify a custom S3 bucket, no sandbox storage resource will be created. The provided custom S3 bucket will be used, even in the sandbox environment. | ||
|
||
</Callout> | ||
|
||
```javascript | ||
|
||
import { defineBackend } from '@aws-amplify/backend'; | ||
import { auth } from './auth/resource'; | ||
import { data } from './data/resource'; | ||
|
||
const backend = defineBackend({ | ||
auth, | ||
data, | ||
}); | ||
|
||
//highlight-start | ||
backend.addOutput({ | ||
storage: { | ||
aws_region: "<region>", | ||
bucket_name: "<bucket-name>" | ||
}, | ||
}); | ||
//highlight-end | ||
|
||
``` | ||
|
||
<InlineFilter filters={["javascript", "nextjs", "react", "angular", "vue", "react-native", "android", "swift"]}> | ||
|
||
## Step 3 - Import latest amplify_outputs.json file | ||
|
||
To ensure the local **amplify_outputs.json** file is up-to-date, you can run [the npx ampx generate outputs command](/[platform]/reference/cli-commands/#npx-ampx-generate-outputs) or download the latest **amplify_outputs.json** from the Amplify console as shown below. | ||
|
||
 | ||
|
||
</InlineFilter> | ||
|
||
<InlineFilter filters={["flutter"]}> | ||
|
||
## Step 3 - Import latest amplifyconfiguration.dart file | ||
|
||
To ensure the local **amplifyconfiguration.dart** file is up-to-date, you can run [the npx ampx generate outputs command](/[platform]/reference/cli-commands/#npx-ampx-generate-outputs). | ||
|
||
</InlineFilter> | ||
|
||
Now that you've configured the necessary permissions, you can start using the storage APIs with your chosen S3 bucket. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.