-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
48 lines (41 loc) · 1.52 KB
/
template.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
AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: An Amazon API Gateway HTTP API and an AWS Lambda function.
# Global values that are applied to all applicable resources in this template
Globals:
Function:
CodeUri: ./dist/
Runtime: nodejs14.x
MemorySize: 128
Timeout: 5
Parameters:
AppName:
Description: Name of Application
Type: String
Default: apigw-http-api-lambda
Resources:
HttpApi:
Type: 'AWS::ApiGatewayV2::Api'
Properties:
Name: !Ref AppName
Description: An Amazon API Gateway HTTP API and an AWS Lambda function.
ProtocolType: HTTP
Target: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${LambdaFunction}/invocations
# Lambda Function - uses Globals to define additional configuration values
LambdaFunction:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: !Sub '${AppName}-function'
Handler: index.handler
# Function permissions grant an AWS service or another account permission to use a function
FunctionResourcePermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
Principal: apigateway.amazonaws.com
FunctionName: !Ref LambdaFunction
SourceArn: !Sub 'arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${HttpApi}/*'
Outputs:
HttpApiEndpoint:
Description: The default endpoint for the HTTP API.
Value: !GetAtt HttpApi.ApiEndpoint