-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambda.yml
124 lines (112 loc) · 3.43 KB
/
lambda.yml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
BucketName:
Type: String
Description: Name of the S3 bucket containing the Lambda code
LambdaCodeKey:
Type: String
Description: Key of the Lambda code file in the S3 bucket
ApiGatewayName:
Type: String
Default: resume
ApiGatewayStageName:
Type: String
Default: call
ApiGatewayHTTPMethod:
Type: String
Default: GET
Resources:
ApiGateway:
Type: AWS::ApiGateway::RestApi
Properties:
EndpointConfiguration:
Types:
- REGIONAL
Name: !Ref ApiGatewayName
ApiGatewayRootMethod:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref ApiGateway
ResourceId: !GetAtt ApiGateway.RootResourceId
HttpMethod: !Ref ApiGatewayHTTPMethod
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri: !Sub
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaArn}/invocations
- LambdaArn: !GetAtt LambdaFunction.Arn
ApiGatewayDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn:
- ApiGatewayRootMethod
Properties:
RestApiId: !Ref ApiGateway
StageName: !Ref ApiGatewayStageName
ApiGatewayDomainCertificate:
Type: AWS::CertificateManager::Certificate
Properties:
DomainName: "*.shaiqkar.dev"
ValidationMethod: EMAIL
ApiGatewayDomainName:
Type: AWS::ApiGatewayV2::DomainName
Properties:
DomainName: resume.shaiqkar.dev
DomainNameConfigurations:
- CertificateArn: !Ref ApiGatewayDomainCertificate
ApiGatewayApiMapping:
Type: AWS::ApiGatewayV2::ApiMapping
Properties:
ApiId: !Ref ApiGateway
DomainName: !Ref ApiGatewayDomainName
Stage: !Ref ApiGatewayStageName
ApiMappingKey: ""
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: resume
Runtime: nodejs20.x
Handler: resume.handler
Role: !GetAtt LambdaExecutionRole.Arn
Code:
S3Bucket: !Ref BucketName
S3Key: !Ref LambdaCodeKey
Environment:
Variables:
BUCKET: !Ref BucketName
LambdaApiGatewayInvoke:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
FunctionName: !GetAtt LambdaFunction.Arn
Principal: apigateway.amazonaws.com
SourceArn: !Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGateway}/${ApiGatewayStageName}/${ApiGatewayHTTPMethod}/
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
RoleName: RoleForResumeLambdaExecution
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- s3:GetObject
- s3:ListBucket
Effect: Allow
Resource:
- !Sub arn:aws:s3:::${BucketName}
- !Sub arn:aws:s3:::${BucketName}/*
PolicyName: AwsAccessForResumeLambda
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Outputs:
ApiGatewayDomainName:
Description: The domain name of the API Gateway
Value: !Ref ApiGatewayDomainName