generated from ModusCreateOrg/template
-
Notifications
You must be signed in to change notification settings - Fork 0
POST /api/reports #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b3c492a
POST /api/reports
GuidoBR 4a402db
Create S3 bucket for file uploads
GuidoBR 34bbfe6
Create S3 bucket for file uploads
GuidoBR 1dac961
Update with main
GuidoBR db77bf8
Merge branch 'main' of github.com:ModusCreateOrg/app-med-ai-gen into …
GuidoBR b2be3a1
Update to filePath
GuidoBR dd8b7e9
Removing date
GuidoBR c09747b
Add policy for ECS Container to access S3 Bucket
GuidoBR 3ff2f64
Add policy for ECS Container to access S3 Bucket
GuidoBR 20d9f0c
Remove unecessary configs
GuidoBR a52e297
Remove lifecycle
GuidoBR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import * as apigateway from 'aws-cdk-lib/aws-apigateway'; | |
| import * as servicediscovery from 'aws-cdk-lib/aws-servicediscovery'; | ||
| import * as iam from 'aws-cdk-lib/aws-iam'; | ||
| import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2'; | ||
| import * as s3 from 'aws-cdk-lib/aws-s3'; | ||
| import * as ssm from 'aws-cdk-lib/aws-ssm'; | ||
|
|
||
| import { Construct } from 'constructs'; | ||
|
|
@@ -528,6 +529,97 @@ export class BackendStack extends cdk.Stack { | |
| ], | ||
| }); | ||
|
|
||
| // Create S3 bucket for file uploads | ||
| const uploadBucket = new s3.Bucket(this, `${appName}UploadBucket-${props.environment}`, { | ||
| bucketName: `${appName.toLowerCase()}-uploads-${props.environment}-${this.account}`, | ||
| removalPolicy: RemovalPolicy.RETAIN, | ||
| versioned: true, // Enable versioning in production | ||
| lifecycleRules: [ | ||
| { | ||
| noncurrentVersionExpiration: cdk.Duration.days(7), | ||
| // Move objects to infrequent access after 30 days | ||
| transitions: [ | ||
| { | ||
| storageClass: s3.StorageClass.INFREQUENT_ACCESS, | ||
| transitionAfter: cdk.Duration.days(30), | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| cors: [ | ||
| { | ||
| allowedMethods: [ | ||
| s3.HttpMethods.GET, | ||
| s3.HttpMethods.POST, | ||
| s3.HttpMethods.PUT, | ||
| s3.HttpMethods.DELETE, | ||
| ], | ||
| allowedOrigins: ['*'], // In production, you should restrict this to your domain | ||
| allowedHeaders: ['*'], | ||
| maxAge: 3000, | ||
| }, | ||
| ], | ||
| blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, // Block all public access for security | ||
| }); | ||
|
|
||
| // Create a policy for authenticated users to upload files | ||
adamrefaey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const uploadPolicy = new iam.PolicyStatement({ | ||
| effect: iam.Effect.ALLOW, | ||
| actions: ['s3:PutObject', 's3:GetObject', 's3:DeleteObject'], | ||
| resources: [`${uploadBucket.bucketArn}/*`], | ||
| conditions: { | ||
| // Restrict uploads to PDF and JPG files | ||
| StringLike: { | ||
| 's3:x-amz-content-type': ['application/pdf', 'image/jpeg', 'image/jpg'], | ||
|
||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Create an IAM role for authenticated users | ||
| const authenticatedRole = new iam.Role( | ||
| this, | ||
| `${appName}AuthenticatedRole-${props.environment}`, | ||
| { | ||
| assumedBy: new iam.FederatedPrincipal( | ||
| 'cognito-identity.amazonaws.com', | ||
| { | ||
| StringEquals: { | ||
| 'cognito-identity.amazonaws.com:aud': userPool.userPoolId, | ||
| }, | ||
| 'ForAnyValue:StringLike': { | ||
| 'cognito-identity.amazonaws.com:amr': 'authenticated', | ||
| }, | ||
| }, | ||
| 'sts:AssumeRoleWithWebIdentity', | ||
| ), | ||
| }, | ||
| ); | ||
|
|
||
| // Attach the upload policy to the authenticated role | ||
| authenticatedRole.addToPolicy(uploadPolicy); | ||
|
|
||
| // Add environment variable to the container for the S3 bucket name | ||
| container.addEnvironment('S3_UPLOAD_BUCKET', uploadBucket.bucketName); | ||
|
|
||
| // Grant the task role access to the S3 bucket | ||
| uploadBucket.grantReadWrite(taskRole); | ||
|
|
||
| // Add more specific S3 permissions for file processing | ||
| taskRole.addToPolicy( | ||
| new iam.PolicyStatement({ | ||
| effect: iam.Effect.ALLOW, | ||
| actions: [ | ||
| 's3:GetObject', | ||
| 's3:PutObject', | ||
| 's3:DeleteObject', | ||
| 's3:ListBucket', | ||
| 's3:GetObjectTagging', | ||
| 's3:PutObjectTagging', | ||
| ], | ||
| resources: [uploadBucket.bucketArn, `${uploadBucket.bucketArn}/*`], | ||
| }), | ||
| ); | ||
|
|
||
| // Outputs | ||
| new cdk.CfnOutput(this, 'ReportsTableName', { | ||
| value: reportsTable.tableName, | ||
|
|
@@ -548,5 +640,11 @@ export class BackendStack extends cdk.Stack { | |
| value: nlb.loadBalancerDnsName, | ||
| description: 'Network Load Balancer DNS Name', | ||
| }); | ||
|
|
||
| // Add S3 bucket name to outputs | ||
| new cdk.CfnOutput(this, 'UploadBucketName', { | ||
| value: uploadBucket.bucketName, | ||
| description: 'S3 Bucket for file uploads', | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we don't need to use versioning.