AWSTemplateFormatVersion: 2010-09-09 Transform: AWS::Serverless-2016-10-31 Description: S3 Uploader - sample application Resources: # HTTP API MyApi: Type: AWS::Serverless::HttpApi Properties: # CORS configuration - this is open for development only and should be restricted in prod. # See https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-httpapi-httpapicorsconfiguration.html CorsConfiguration: AllowMethods: - GET - POST - DELETE - OPTIONS AllowHeaders: - "*" AllowOrigins: - "*" ## Lambda functions UploadRequestFunction: # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction Type: AWS::Serverless::Function Properties: CodeUri: getSignedURL/ Handler: app.handler Runtime: nodejs16.x Timeout: 3 MemorySize: 128 Environment: Variables: UploadBucket: !Ref S3UploadBucket Policies: - S3WritePolicy: BucketName: !Ref S3UploadBucket ## This permission allows the Lambda function to request signed URLs ## for objects that will be publicly readable. Uncomment if you want this ACL. # - Statement: # - Effect: Allow # Resource: !Sub 'arn:aws:s3:::${S3UploadBucket}/' # Action: # - s3:putObjectAcl Events: UploadAssetAPI: Type: HttpApi Properties: Path: /uploads Method: get ApiId: !Ref MyApi ## S3 bucket S3UploadBucket: Type: AWS::S3::Bucket Properties: CorsConfiguration: CorsRules: - AllowedHeaders: - "*" AllowedMethods: - GET - PUT - HEAD AllowedOrigins: - "*" ## Take a note of the outputs for deploying the workflow templates in this sample application Outputs: APIendpoint: Description: "HTTP API endpoint URL" Value: !Sub "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com" S3UploadBucketName: Description: "S3 bucket for application uploads" Value: !Ref 'S3UploadBucket'