Example to add existing SQS queue for subscibing to an SNS topic.
YAML
QueuePolicyLogicalId: CustomQueuePolicyLogicalId QueueArn:
Fn::GetAtt: MyCustomQueue.Arn QueueUrl:
Ref: MyCustomQueue BatchSize: 5
SQS
The object describing an SQS event source type. For more information, see Using AWS Lambda with Amazon SQS in the AWS Lambda Developer Guide.
SAM generates AWS::Lambda::EventSourceMapping resource when this event type is set
Syntax
To declare this entity in your AWS Serverless Application Model (AWS SAM) template, use the following syntax.
YAML
BatchSize: Integer Enabled: Boolean
FilterCriteria: FilterCriteria
MaximumBatchingWindowInSeconds: Integer Queue: String
Properties
BatchSizeThe maximum number of items to retrieve in a single batch.
Type: Integer Required: No Default: 10
AWS CloudFormation compatibility: This property is passed directly to the BatchSize property of an AWS::Lambda::EventSourceMapping resource.
Minimum: 1 Maximum: 10000 Enabled
Disables the event source mapping to pause polling and invocation.
Type: Boolean Required: No
AWS CloudFormation compatibility: This property is passed directly to the Enabled property of an AWS::Lambda::EventSourceMapping resource.
FilterCriteria
A object that defines the criteria to determine whether Lambda should process an event. For more information, see AWS Lambda event filtering in the AWS Lambda Developer Guide.
Type: FilterCriteria Required: No
AWS CloudFormation compatibility: This property is passed directly to the FilterCriteria property of an AWS::Lambda::EventSourceMapping resource.
MaximumBatchingWindowInSeconds
The maximum amount of time, in seconds, to gather records before invoking the function.
Type: Integer Required: No
AWS CloudFormation compatibility: This property is passed directly to the
MaximumBatchingWindowInSeconds property of an AWS::Lambda::EventSourceMapping resource.
Queue
The ARN of the queue.
Type: String Required: Yes
AWS CloudFormation compatibility: This property is passed directly to the EventSourceArn property of an AWS::Lambda::EventSourceMapping resource.
Examples SQS Event
SQS EventYAML
Events:
SQSEvent:
Type: SQS Properties:
Queue: arn:aws:sqs:us-west-2:012345678901:my-queue BatchSize: 10
Enabled: false FilterCriteria:
Filters:
- Pattern: '{"key": ["val1", "val2"]}'
FunctionCode
The deployment package for a Lambda function.
Syntax
To declare this entity in your AWS Serverless Application Model (AWS SAM) template, use the following syntax.
YAML
Bucket: String Key: String Version: String
Properties
Bucket
An Amazon S3 bucket in the same AWS Region as your function.
Type: String Required: Yes
AWS CloudFormation compatibility: This property is passed directly to the S3Bucket property of the AWS::Lambda::Function Code data type.
Key
The Amazon S3 key of the deployment package.
Type: String Required: Yes
AWS CloudFormation compatibility: This property is passed directly to the S3Key property of the AWS::Lambda::Function Code data type.
Version
For versioned objects, the version of the deployment package object to use.
Type: String Required: No
AWS CloudFormation compatibility: This property is passed directly to the S3ObjectVersion property of the AWS::Lambda::Function Code data type.
Examples
FunctionCode
Function Code example
YAML
FunctionCode:
Bucket: mybucket-name Key: mykey-name Version: 121212
AWS::Serverless::HttpApi
Creates an Amazon API Gateway HTTP API, which enables you to create RESTful APIs with lower latency and lower costs than REST APIs. For more information, see Working with HTTP APIs in the API Gateway Developer Guide.
Syntax
To declare this entity in your AWS Serverless Application Model (AWS SAM) template, use the following syntax.
YAML
Type: AWS::Serverless::HttpApi Properties:
AccessLogSettings: AccessLogSettings Auth: HttpApiAuth (p. 141)
CorsConfiguration: String | HttpApiCorsConfiguration (p. 147) DefaultRouteSettings: RouteSettings
DefinitionBody: JSON
DefinitionUri: String | HttpApiDefinition (p. 149) Description: String
DisableExecuteApiEndpoint: Boolean
Domain: HttpApiDomainConfiguration (p. 150) FailOnWarnings: Boolean
RouteSettings: RouteSettings StageName: String
StageVariables: Json Tags: Map
Properties
AccessLogSettings
The settings for access logging in a stage.
Type: AccessLogSettings Required: No
AWS CloudFormation compatibility: This property is passed directly to the AccessLogSettings property of an AWS::ApiGatewayV2::Stage resource.
Auth
Configures authorization for controlling access to your API Gateway HTTP API.
For more information, see Controlling access to HTTP APIs with JWT authorizers in the API Gateway Developer Guide.
Type: HttpApiAuth (p. 141) Required: No
AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent.
CorsConfiguration
Manages cross-origin resource sharing (CORS) for all your API Gateway HTTP APIs. Specify the domain to allow as a string, or specify an HttpApiCorsConfiguration object. Note that CORS requires AWS SAM to modify your OpenAPI definition, so CORS works only if the DefinitionBody property is specified.
For more information, see Configuring CORS for an HTTP API in the API Gateway Developer Guide.
Note: If CorsConfiguration is set both in an OpenAPI definition and at the property level, then AWS SAM merges both configuration sources with the properties taking precedence.
Note: If this property is set to true, then all origins are allowed.
Type: String | HttpApiCorsConfiguration (p. 147)
Required: No
AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent.
DefaultRouteSettings
The default route settings for this HTTP API. These settings apply to all routes unless overridden by the RouteSettings property for certain routes.
Type: RouteSettings Required: No
AWS CloudFormation compatibility: This property is passed directly to the RouteSettings property of an AWS::ApiGatewayV2::Stage resource.
DefinitionBody
The OpenAPI definition that describes your HTTP API. If you don't specify a DefinitionUri or a DefinitionBody, AWS SAM generates a DefinitionBody for you based on your template configuration.
Type: JSON Required: No
AWS CloudFormation compatibility: This property is similar to the Body property of an
AWS::ApiGatewayV2::Api resource. If certain properties are provided, AWS SAM may insert content into or modify the DefinitionBody before it is passed to AWS CloudFormation.
Properties include Auth and an EventSource of type HttpApi for a corresponding AWS::Serverless::Function resource.
DefinitionUri
The Amazon Simple Storage Service (Amazon S3) URI, local file path, or location object of the the OpenAPI definition that defines the HTTP API. The Amazon S3 object that this property references must be a valid OpenAPI definition file. If you don't specify a DefinitionUri or a DefinitionBody are specified, AWS SAM generates a DefinitionBody for you based on your template configuration.
If you provide a local file path, the template must go through the workflow that includes the sam deploy or sam package command for the definition to be transformed properly.
Intrinsic functions are not supported in external OpenApi definition files that you reference with DefinitionUri. To import an OpenApi definition into the template, use the DefinitionBody property with the Include transform.
Type: String | HttpApiDefinition (p. 149) Required: No
AWS CloudFormation compatibility: This property is similar to the BodyS3Location property of an AWS::ApiGatewayV2::Api resource. The nested Amazon S3 properties are named differently.
Description
A description of the HttpApi resource.
Note: This property requires AWS SAM to modify the HttpApi resource's OpenAPI definition, to set the description field. The following two scenarios result in an error: 1) The DefinitionBody property is specified with the description field set in the OpenAPI definition (since this is a conflict that AWS SAM won't resolve), or 2) The DefinitionUri property is specified (since AWS SAM won't modify an OpenAPI definition that it retrieves from Amazon S3).
Type: String Required: No
AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent.
DisableExecuteApiEndpoint
Specifies whether clients can invoke your HTTP API by using the default execute-api endpoint https://{api_id}.execute-api.{region}.amazonaws.com. By default, clients can invoke your API with the default endpoint. To require that clients only use a custom domain name to invoke your API, disable the default endpoint.
Type: Boolean Required: No
AWS CloudFormation compatibility: This property is passed directly to the
DisableExecuteApiEndpoint property of an AWS::ApiGatewayV2::Api resource.
Domain
Configures a custom domain for this API Gateway HTTP API.
Type: HttpApiDomainConfiguration (p. 150) Required: No
AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent.
FailOnWarnings
Specifies whether to roll back the HTTP API creation (true) or not (false) when a warning is encountered. The default value is false.
Type: Boolean Required: No
AWS CloudFormation compatibility: This property is passed directly to the FailOnWarnings property of an AWS::ApiGatewayV2::Api resource.
RouteSettings
The route settings, per route, for this HTTP API. For more information, see Working with routes for HTTP APIs in the API Gateway Developer Guide.
Type: RouteSettings Required: No
AWS CloudFormation compatibility: This property is passed directly to the RouteSettings property of an AWS::ApiGatewayV2::Stage resource.
StageName
The name of the API stage. If no name is specified, AWS SAM uses the $default stage from API Gateway.
Type: String Required: No Default: $default
AWS CloudFormation compatibility: This property is passed directly to the StageName property of an AWS::ApiGatewayV2::Stage resource.
StageVariables
A map that defines the stage variables. Variable names can have alphanumeric and underscore characters. The values must match [A-Za-z0-9-._~:/?#&=,]+.
Type: Json Required: No
AWS CloudFormation compatibility: This property is passed directly to the StageVariables property of an AWS::ApiGatewayV2::Stage resource.
Tags
A map (string to string) that specifies the tags to add to this API Gateway stage. Keys can be 1 to 128 Unicode characters in length and cannot include the prefix aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -. Values can be 1 to 256 Unicode characters in length.
Type: Map Required: No
AWS CloudFormation compatibility: This property is unique to AWS SAM and doesn't have an AWS CloudFormation equivalent.
Additional notes: The Tags property requires AWS SAM to modify your OpenAPI definition, so tags are added only if the DefinitionBody property is specified—no tags are
added if the DefinitionUri property is specified. AWS SAM automatically adds an
httpapi:createdBy:SAM tag. Tags are also added to the AWS::ApiGatewayV2::Stage resource and the AWS::ApiGatewayV2::DomainName resource (if DomainName is specified).
Return Values
Ref
When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the API ID of the underlying AWS::ApiGatewayV2::Api resource, for example, a1bcdef2gh.
For more information about using the Ref function, see Ref in the AWS CloudFormation User Guide.