AWS SAM(Serverless Application Model)是一种用于构建和部署无服务器应用程序的开发框架。它可以管理许多AWS服务,包括但不限于以下几种:
示例代码:
Resources:
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: my-lambda-function/
Handler: index.handler
Runtime: nodejs14.x
示例代码:
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody:
swagger: "2.0"
info:
title: "My API"
version: "1.0.0"
paths:
/hello:
get:
responses:
'200':
description: 'OK'
schema:
type: 'string'
x-amazon-apigateway-integration:
type: 'AWS_PROXY'
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaFunction.Arn}/invocations
示例代码:
Resources:
MyTable:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: MyTable
PrimaryKey:
Name: id
Type: String
示例代码:
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-bucket
示例代码:
Resources:
MyStateMachine:
Type: AWS::StepFunctions::StateMachine
Properties:
DefinitionString:
Fn::Sub:
- |
{
"Comment": "A Hello World example of the Amazon States Language using a Pass state",
"StartAt": "HelloWorld",
"States": {
"HelloWorld": {
"Type": "Pass",
"Result": "Hello, World!",
"End": true
}
}
}
- {}
这些只是AWS SAM可以管理的一小部分服务,您还可以使用AWS SAM来管理许多其他服务,例如Amazon SQS、Amazon SNS、Amazon Kinesis等。