在项目根目录下找到amplify/backend/auth/yourAuthIndenittyPoolID/yourAuthIndenittyPoolID-cloudformation-template.yml文件,在Resources下添加以下内容:
YOUR_API_NAMEUnauthRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: "YOUR_API_NAMEUnauthRole"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Federated:
"cognito-identity.amazonaws.com": true
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud":
"YOUR_AUTH_IDENTITY_POOL_ID"
"ForAnyValue:StringLike":
"cognito-identity.amazonaws.com:amr":
"unauthenticated"
Path: "/"
Policies:
- PolicyName: "YOUR_API_NAMEUnauthRolePolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "execute-api:Invoke"
Resource:
- "arn:aws:execute-api:YOUR_REGION:YOUR_ACCOUNT_ID:YOUR_API_GATEWAY_ID/*/*/*"
YOUR_API_NAMEAuthRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: "YOUR_API_NAMEAuthRole"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Federated:
"cognito-identity.amazonaws.com": true
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud":
"YOUR_AUTH_IDENTITY_POOL_ID"
"ForAnyValue:StringLike":
"cognito-identity.amazonaws.com:amr":
"authenticated"
Path: "/"
Policies:
- PolicyName: "YOUR_API_NAMEAuthRolePolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- "execute-api:Invoke"
Resource:
- "arn:aws:execute-api:YOUR_REGION:YOUR_ACCOUNT_ID:YOUR_API_GATEWAY_ID/*/*/*"
其中,YOUR_API_NAME、YOUR_REGION、YOUR_ACCOUNT_ID、YOUR_API_GATEWAY_ID、YOUR_AUTH_IDENTITY_POOL_ID需要替换成您自己的信息。
然后再运行'amplify push”命令,即可成功部署