How do I deploy a lambda Java function with an API gateway REST interface including caching POST methods using AWS Serverless Application Model?
Asked
Active
Viewed 523 times
1 Answers
0
ExampleFunction:
# 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: path/to/libs/example.jar
Handler: com.example.Example::handleRequest
VpcConfig:
SecurityGroupIds:
- sg-abc
SubnetIds:
- subnet-1234
- subnet-1235
- subnet-1236
Runtime: java11
MemorySize: 1024
Events:
Example:
# More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Type: Api
Properties:
Path: /example
Method: post
RestApiId:
Ref: ExampleApi
ExampleApi:
Type: AWS::Serverless::Api
Properties:
Description: Example Private API with cache and logging disabled
StageName: prod
# Cache size is in GB
CacheClusterSize: '0.5'
CacheClusterEnabled: true
# First method is for default / GET, second is for POST
MethodSettings:
- CachingEnabled: true
CacheDataEncrypted: true
CacheTtlInSeconds: 3600
LoggingLevel: 'Off'
HttpMethod: '*'
ResourcePath: '/*'
MetricsEnabled: true
- CachingEnabled: true
CacheDataEncrypted: true
CacheTtlInSeconds: 3600
LoggingLevel: 'Off'
HttpMethod: 'POST'
# For encoding see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-stage-methodsetting.html#cfn-apigateway-stage-methodsetting-resourcepath
ResourcePath: '/~1example'
MetricsEnabled: true
ThrottlingRateLimit: 1000
ThrottlingBurstLimit: 500
Auth:
ResourcePolicy:
CustomStatements: [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "execute-api:/*"
}
]
EndpointConfiguration:
Type: PRIVATE

Tim
- 31,888
- 7
- 52
- 78