forked from aws-samples/amazon-s3-presigned-urls-aws-sam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
77 lines (72 loc) · 2.28 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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: nodejs12.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'