在使用 Amplify Storage API 时,需要给 Group Pool 中的受保护文件添加相应的权限,并在代码中使用 AWS Identity and Access Management (IAM) 对象进行身份验证。以下是示例代码:
// 添加权限 { "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::mybucket/prefix/*", "Condition": { "ObjectExists": "true" } }
// 身份验证 import Amplify, { Auth } from 'aws-amplify';
Amplify.configure({ Auth: { identityPoolId: 'IDENTITY_POOL_ID', region: 'REGION', userPoolId: 'USER_POOL_ID', userPoolWebClientId: 'USER_POOL_WEB_CLIENT_ID' } });
Auth.signIn(username, password) .then(user => { console.log(user); }) .catch(err => { console.log(err); });