|
| 1 | +from aws_cdk import cdk |
| 2 | +from aws_cdk import aws_lambda as lambda_, aws_s3 as s3 |
| 3 | + |
| 4 | +from cognito_chat_room_pool import CognitoChatRoomPool |
| 5 | +from dynamodb_posts_table import DynamoPostsTable |
| 6 | + |
| 7 | + |
| 8 | +class ChatAppFunction(lambda_.Function): |
| 9 | + def __init__( |
| 10 | + self, scope: cdk.Construct, id: str, *, bucket: s3.IBucket, zip_file: str |
| 11 | + ): |
| 12 | + super().__init__( |
| 13 | + scope, |
| 14 | + id, |
| 15 | + code=lambda_.S3Code(bucket, zip_file), |
| 16 | + runtime=lambda_.Runtime.NODE_J_S610, |
| 17 | + handler="index.handler", |
| 18 | + ) |
| 19 | + |
| 20 | + |
| 21 | +class MyStack(cdk.Stack): |
| 22 | + def __init__(self, scope: cdk.App, id: str, **kwargs): |
| 23 | + super().__init__(scope, id, **kwargs) |
| 24 | + |
| 25 | + DynamoPostsTable(self, "Posts") |
| 26 | + CognitoChatRoomPool(self, "UserPool") |
| 27 | + |
| 28 | + bucket = s3.Bucket.import_(self, "DougsBucket", bucket_name="dogs-chat-app") |
| 29 | + |
| 30 | + ChatAppFunction( |
| 31 | + self, |
| 32 | + "StartAddBucket", |
| 33 | + bucket=bucket, |
| 34 | + zip_file="StartAddingPendingCognitoUser.zip", |
| 35 | + ) |
| 36 | + |
| 37 | + ChatAppFunction( |
| 38 | + self, |
| 39 | + "FinishAddBucket", |
| 40 | + bucket=bucket, |
| 41 | + zip_file="FinishAddingPendingCognitoUser.zip", |
| 42 | + ) |
| 43 | + |
| 44 | + ChatAppFunction( |
| 45 | + self, |
| 46 | + "SignInUserBucket", |
| 47 | + bucket=bucket, |
| 48 | + zip_file="SignInCognitoUser.zip", |
| 49 | + ) |
| 50 | + |
| 51 | + ChatAppFunction( |
| 52 | + self, |
| 53 | + "VerifyBucket", |
| 54 | + bucket=bucket, |
| 55 | + zip_file="VerifyCognitoSignIn.zip", |
| 56 | + ) |
| 57 | + |
| 58 | + ChatAppFunction( |
| 59 | + self, |
| 60 | + "StartChangeBucket", |
| 61 | + bucket=bucket, |
| 62 | + zip_file="StartChangingForgottenCognitoUserPassword.zip", |
| 63 | + ) |
| 64 | + |
| 65 | + ChatAppFunction( |
| 66 | + self, |
| 67 | + "FinishChangeBucket", |
| 68 | + bucket=bucket, |
| 69 | + zip_file="FinishChangingForgottenCognitoUserPassword.zip", |
| 70 | + ) |
| 71 | + |
| 72 | + ChatAppFunction( |
| 73 | + self, |
| 74 | + "GetPostsBucket", |
| 75 | + bucket=bucket, |
| 76 | + zip_file="GetPosts.zip", |
| 77 | + ) |
| 78 | + |
| 79 | + ChatAppFunction( |
| 80 | + self, |
| 81 | + "AddPostBucket", |
| 82 | + bucket=bucket, |
| 83 | + zip_file="AddPost.zip", |
| 84 | + ) |
| 85 | + |
| 86 | + ChatAppFunction( |
| 87 | + self, |
| 88 | + "DeletePostBucket", |
| 89 | + bucket=bucket, |
| 90 | + zip_file="DeletePost.zip", |
| 91 | + ) |
| 92 | + |
| 93 | + ChatAppFunction( |
| 94 | + self, |
| 95 | + "DeleteUserBucket", |
| 96 | + bucket=bucket, |
| 97 | + zip_file="DeleteCognitoUser.zip", |
| 98 | + ) |
| 99 | + |
| 100 | + |
| 101 | +app = cdk.App() |
| 102 | + |
| 103 | +# Add the stack to the app |
| 104 | +# (Apps can hot many stacks, for example, one for each region) |
| 105 | +MyStack(app, "ChatAppStack", env={"region": "us-west-2"}) |
| 106 | + |
| 107 | +app.run() |
0 commit comments