-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up our Serverless infrastructure
- Loading branch information
Showing
5 changed files
with
187 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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,92 @@ | ||
Resources: | ||
# The federated identity for our user pool to auth with | ||
CognitoIdentityPool: | ||
Type: AWS::Cognito::IdentityPool | ||
Properties: | ||
# Generate a name based on the stage | ||
IdentityPoolName: ${self:custom.stage}IdentityPool | ||
# Don't allow unathenticated users | ||
AllowUnauthenticatedIdentities: false | ||
# Link to our User Pool | ||
CognitoIdentityProviders: | ||
- ClientId: | ||
Ref: CognitoUserPoolClient | ||
ProviderName: | ||
Fn::GetAtt: [ "CognitoUserPool", "ProviderName" ] | ||
|
||
# IAM roles | ||
CognitoIdentityPoolRoles: | ||
Type: AWS::Cognito::IdentityPoolRoleAttachment | ||
Properties: | ||
IdentityPoolId: | ||
Ref: CognitoIdentityPool | ||
Roles: | ||
authenticated: | ||
Fn::GetAtt: [CognitoAuthRole, Arn] | ||
|
||
# IAM role used for authenticated users | ||
CognitoAuthRole: | ||
Type: AWS::IAM::Role | ||
Properties: | ||
Path: / | ||
AssumeRolePolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: 'Allow' | ||
Principal: | ||
Federated: 'cognito-identity.amazonaws.com' | ||
Action: | ||
- 'sts:AssumeRoleWithWebIdentity' | ||
Condition: | ||
StringEquals: | ||
'cognito-identity.amazonaws.com:aud': | ||
Ref: CognitoIdentityPool | ||
'ForAnyValue:StringLike': | ||
'cognito-identity.amazonaws.com:amr': authenticated | ||
Policies: | ||
- PolicyName: 'CognitoAuthorizedPolicy' | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: 'Allow' | ||
Action: | ||
- 'mobileanalytics:PutEvents' | ||
- 'cognito-sync:*' | ||
- 'cognito-identity:*' | ||
Resource: '*' | ||
|
||
# Allow users to invoke our API | ||
- Effect: 'Allow' | ||
Action: | ||
- 'execute-api:Invoke' | ||
Resource: | ||
Fn::Join: | ||
- '' | ||
- | ||
- 'arn:aws:execute-api:' | ||
- Ref: AWS::Region | ||
- ':' | ||
- Ref: AWS::AccountId | ||
- ':' | ||
- Ref: ApiGatewayRestApi | ||
- '/*' | ||
|
||
# Allow users to upload attachments to their | ||
# folder inside our S3 bucket | ||
- Effect: 'Allow' | ||
Action: | ||
- 's3:*' | ||
Resource: | ||
- Fn::Join: | ||
- '' | ||
- | ||
- Fn::GetAtt: [AttachmentsBucket, Arn] | ||
- '/private/' | ||
- '$' | ||
- '{cognito-identity.amazonaws.com:sub}/*' | ||
|
||
# Print out the Id of the Identity Pool that is created | ||
Outputs: | ||
IdentityPoolId: | ||
Value: | ||
Ref: CognitoIdentityPool |
This file contains 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,32 @@ | ||
Resources: | ||
CognitoUserPool: | ||
Type: AWS::Cognito::UserPool | ||
Properties: | ||
# Generate a name based on the stage | ||
UserPoolName: ${self:custom.stage}-user-pool | ||
# Set email as an alias | ||
UsernameAttributes: | ||
AutoVerifiedAttributes: | ||
|
||
CognitoUserPoolClient: | ||
Type: AWS::Cognito::UserPoolClient | ||
Properties: | ||
# Generate an app client name based on the stage | ||
ClientName: ${self:custom.stage}-user-pool-client | ||
UserPoolId: | ||
Ref: CognitoUserPool | ||
ExplicitAuthFlows: | ||
- ADMIN_NO_SRP_AUTH | ||
GenerateSecret: false | ||
|
||
# Print out the Id of the User Pool that is created | ||
Outputs: | ||
UserPoolId: | ||
Value: | ||
Ref: CognitoUserPool | ||
|
||
UserPoolClientId: | ||
Value: | ||
Ref: CognitoUserPoolClient |
This file contains 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,17 @@ | ||
Resources: | ||
NotesTable: | ||
Type: AWS::DynamoDB::Table | ||
Properties: | ||
TableName: ${self:custom.tableName} | ||
AttributeDefinitions: | ||
- AttributeName: userId | ||
AttributeType: S | ||
- AttributeName: noteId | ||
AttributeType: S | ||
KeySchema: | ||
- AttributeName: userId | ||
KeyType: HASH | ||
- AttributeName: noteId | ||
KeyType: RANGE | ||
# Set the capacity to auto-scale | ||
BillingMode: PAY_PER_REQUEST |
This file contains 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,25 @@ | ||
Resources: | ||
AttachmentsBucket: | ||
Type: AWS::S3::Bucket | ||
Properties: | ||
# Set the CORS policy | ||
CorsConfiguration: | ||
CorsRules: | ||
- | ||
AllowedOrigins: | ||
- '*' | ||
AllowedHeaders: | ||
- '*' | ||
AllowedMethods: | ||
- GET | ||
- PUT | ||
- POST | ||
- DELETE | ||
- HEAD | ||
MaxAge: 3000 | ||
|
||
# Print out the name of the bucket that is created | ||
Outputs: | ||
AttachmentsBucketName: | ||
Value: | ||
Ref: AttachmentsBucket |
This file contains 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