mirror of
https://github.com/swift-server/swift-openapi-lambda.git
synced 2026-05-03 07:22:26 +00:00
c72834d93c
- Update this library to support the upcoming release of AWS Lambda Runtime for Swift v2. This change affects the public API (some `Sendable` added) and requires a major version bump. I propose to release v2 to align this library's major with the Swift AWS Lambda Runtime's major. - Add a QuoteAPI example in the `Examples` directory
82 lines
2.4 KiB
YAML
82 lines
2.4 KiB
YAML
AWSTemplateFormatVersion: '2010-09-09'
|
|
Transform: AWS::Serverless-2016-10-31
|
|
Description: SAM Template for QuoteService
|
|
|
|
Globals:
|
|
Function:
|
|
Timeout: 60
|
|
CodeUri: .
|
|
Handler: swift.bootstrap
|
|
Runtime: provided.al2
|
|
MemorySize: 128
|
|
Architectures:
|
|
- arm64
|
|
|
|
Resources:
|
|
# QuoteService Lambda function
|
|
QuoteService:
|
|
Type: AWS::Serverless::Function
|
|
Properties:
|
|
Environment:
|
|
Variables:
|
|
# by default, AWS Lambda runtime produces no log
|
|
# use `LOG_LEVEL: debug` for for lifecycle and event handling information
|
|
# use `LOG_LEVEL: trace` for detailed input event information
|
|
LOG_LEVEL: trace
|
|
|
|
Events:
|
|
# pass through all HTTP verbs and paths
|
|
Api:
|
|
Type: HttpApi
|
|
Properties:
|
|
ApiId: !Ref MyProtectedApi
|
|
Path: /{proxy+}
|
|
Method: ANY
|
|
|
|
Metadata:
|
|
BuildMethod: makefile
|
|
|
|
# Lambda authorizer function
|
|
LambdaAuthorizer:
|
|
Type: AWS::Serverless::Function
|
|
Properties:
|
|
Timeout: 29 # max 29 seconds for Lambda authorizers
|
|
Environment:
|
|
Variables:
|
|
# by default, AWS Lambda runtime produces no log
|
|
# use `LOG_LEVEL: debug` for for lifecycle and event handling information
|
|
# use `LOG_LEVEL: trace` for detailed input event information
|
|
LOG_LEVEL: trace
|
|
Metadata:
|
|
BuildMethod: makefile
|
|
|
|
# The API Gateway
|
|
MyProtectedApi:
|
|
Type: AWS::Serverless::HttpApi
|
|
Properties:
|
|
Auth:
|
|
DefaultAuthorizer: MyLambdaAuthorizer
|
|
Authorizers:
|
|
MyLambdaAuthorizer:
|
|
FunctionArn: !GetAtt LambdaAuthorizer.Arn
|
|
Identity:
|
|
Headers:
|
|
- Authorization
|
|
AuthorizerPayloadFormatVersion: "2.0"
|
|
EnableSimpleResponses: true
|
|
|
|
# Give the API Gateway permissions to invoke the Lambda authorizer
|
|
AuthorizerPermission:
|
|
Type: AWS::Lambda::Permission
|
|
Properties:
|
|
Action: lambda:InvokeFunction
|
|
FunctionName: !Ref LambdaAuthorizer
|
|
Principal: apigateway.amazonaws.com
|
|
SourceArn: !Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MyProtectedApi}/*
|
|
|
|
# print API endpoint
|
|
Outputs:
|
|
SwiftAPIEndpoint:
|
|
Description: "API Gateway endpoint URL for your application"
|
|
Value: !Sub "https://${MyProtectedApi}.execute-api.${AWS::Region}.amazonaws.com"
|