|
| 1 | +Resources: |
| 2 | + # The federated identity for our user pool to auth with |
| 3 | + CognitoIdentityPool: |
| 4 | + Type: AWS::Cognito::IdentityPool |
| 5 | + Properties: |
| 6 | + # Generate a name based on the stage |
| 7 | + IdentityPoolName: ${self:custom.stage}IdentityPool |
| 8 | + # Don't allow unathenticated users |
| 9 | + AllowUnauthenticatedIdentities: false |
| 10 | + # Link to our User Pool |
| 11 | + CognitoIdentityProviders: |
| 12 | + - ClientId: |
| 13 | + Ref: CognitoUserPoolClient |
| 14 | + ProviderName: |
| 15 | + Fn::GetAtt: [ "CognitoUserPool", "ProviderName" ] |
| 16 | + |
| 17 | + # IAM roles |
| 18 | + CognitoIdentityPoolRoles: |
| 19 | + Type: AWS::Cognito::IdentityPoolRoleAttachment |
| 20 | + Properties: |
| 21 | + IdentityPoolId: |
| 22 | + Ref: CognitoIdentityPool |
| 23 | + Roles: |
| 24 | + authenticated: |
| 25 | + Fn::GetAtt: [CognitoAuthRole, Arn] |
| 26 | + |
| 27 | + # IAM role used for authenticated users |
| 28 | + CognitoAuthRole: |
| 29 | + Type: AWS::IAM::Role |
| 30 | + Properties: |
| 31 | + Path: / |
| 32 | + AssumeRolePolicyDocument: |
| 33 | + Version: '2012-10-17' |
| 34 | + Statement: |
| 35 | + - Effect: 'Allow' |
| 36 | + Principal: |
| 37 | + Federated: 'cognito-identity.amazonaws.com' |
| 38 | + Action: |
| 39 | + - 'sts:AssumeRoleWithWebIdentity' |
| 40 | + Condition: |
| 41 | + StringEquals: |
| 42 | + 'cognito-identity.amazonaws.com:aud': |
| 43 | + Ref: CognitoIdentityPool |
| 44 | + 'ForAnyValue:StringLike': |
| 45 | + 'cognito-identity.amazonaws.com:amr': authenticated |
| 46 | + Policies: |
| 47 | + - PolicyName: 'CognitoAuthorizedPolicy' |
| 48 | + PolicyDocument: |
| 49 | + Version: '2012-10-17' |
| 50 | + Statement: |
| 51 | + - Effect: 'Allow' |
| 52 | + Action: |
| 53 | + - 'mobileanalytics:PutEvents' |
| 54 | + - 'cognito-sync:*' |
| 55 | + - 'cognito-identity:*' |
| 56 | + Resource: '*' |
| 57 | + |
| 58 | + # Allow users to invoke our API |
| 59 | + - Effect: 'Allow' |
| 60 | + Action: |
| 61 | + - 'execute-api:Invoke' |
| 62 | + Resource: |
| 63 | + Fn::Join: |
| 64 | + - '' |
| 65 | + - |
| 66 | + - 'arn:aws:execute-api:' |
| 67 | + - Ref: AWS::Region |
| 68 | + - ':' |
| 69 | + - Ref: AWS::AccountId |
| 70 | + - ':' |
| 71 | + - Ref: ApiGatewayRestApi |
| 72 | + - '/*' |
| 73 | + |
| 74 | + # Allow users to upload attachments to their |
| 75 | + # folder inside our S3 bucket |
| 76 | + - Effect: 'Allow' |
| 77 | + Action: |
| 78 | + - 's3:*' |
| 79 | + Resource: |
| 80 | + - Fn::Join: |
| 81 | + - '' |
| 82 | + - |
| 83 | + - Fn::GetAtt: [AttachmentsBucket, Arn] |
| 84 | + - '/private/' |
| 85 | + - '$' |
| 86 | + - '{cognito-identity.amazonaws.com:sub}/*' |
| 87 | + |
| 88 | +# Print out the Id of the Identity Pool that is created |
| 89 | +Outputs: |
| 90 | + IdentityPoolId: |
| 91 | + Value: |
| 92 | + Ref: CognitoIdentityPool |
0 commit comments