Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Resources:
Type: CloudWatchEvent
Description: Detects EC2 Security Group Events to Send to Teams
Properties:
EventBusName: event-bus-name
Pattern:
source:
- "aws.ec2"
Expand Down
17 changes: 17 additions & 0 deletions examples/2016-10-31/lambda_edge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ LambdaEdgeFunctionSample:
AutoPublishAlias: live
```

This also uses `ProvisionedConcurrencyConfig` setting on the lambda function Alias created by AutoPublishAlias:

```yaml
LambdaEdgeFunctionSample:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Runtime: nodejs6.10
Handler: index.handler
Role: !GetAtt LambdaEdgeFunctionRole.Arn
Timeout: 5
# More info at https://github.com/awslabs/serverless-application-model/blob/master/docs/safe_lambda_deployments.rst
AutoPublishAlias: live
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: !If [AliasProvisionedConcurrencyEnabled, !Ref ProvisionedConcurrency, !Ref 'AWS::NoValue']
```

We must also create a custom IAM Role which allows `lambda.amazonaws.com` and `edgelambda.amazonaws.com` services to assume the role and execute the function.

```yaml
Expand Down
18 changes: 18 additions & 0 deletions examples/2016-10-31/lambda_edge/template.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Sample SAM configuration for Lambda@Edge to ease deployment and further updates
Parameters:

ProvisionedConcurrency:
Type: String
Default: 10
EnableAliasProvisionedConcurrency:
Type: String
AllowedValues:
- true
- false
Default: true

Globals:

Function:
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: !If [AliasProvisionedConcurrencyEnabled, !Ref ProvisionedConcurrency, !Ref 'AWS::NoValue']

Resources:

CFDistribution:
Expand Down
14 changes: 13 additions & 1 deletion examples/2016-10-31/stream_processor/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,33 @@ Resources:
Handler: index.handler
Runtime: nodejs10.x
CodeUri: src/
Policies:
- SNSPublishMessagePolicy:
TopicName: !GetAtt MySnsTopic.TopicName
Events:
Stream:
Type: Kinesis
Properties:
Stream: !GetAtt Stream.Arn
MaximumBatchingWindowInSeconds: 20
ParallelizationFactor: 8
MaximumRetryAttempts: 100
BisectBatchOnFunctionError: true
MaximumRecordAgeInSeconds: 604800
StartingPosition: TRIM_HORIZON
DestinationConfig:
OnFailure:
Destination: !Ref MySnsTopic

Stream:
Type: AWS::Kinesis::Stream
Properties:
ShardCount: 1

Outputs:
MySnsTopic:
Type: AWS::SNS::Topic

Outputs:
KinesisStream:
Description: "Kinesis Stream that will trigger Lambda function upon new records"
Value: !GetAtt Stream.Arn

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/apps/inbound-ses-spam-filter/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Description: >-
Parameters:
IdentityNameParameter:
Type: String
Outputs:
InboundSESSpamFilterFunction:
Description: "inboundsesspamfilter Lambda Function ARN"
Value: !GetAtt inboundsesspamfilter.Arn
Resources:
inboundsesspamfilter:
Type: 'AWS::Serverless::Function'
Expand Down
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.15.1'
__version__ = '1.18.0'
1 change: 1 addition & 0 deletions samtranslator/model/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class EventsRule(Resource):
resource_type = 'AWS::Events::Rule'
property_types = {
'Description': PropertyType(False, is_str()),
'EventBusName': PropertyType(False, is_str()),
'EventPattern': PropertyType(False, is_type(dict)),
'Name': PropertyType(False, is_str()),
'RoleArn': PropertyType(False, is_str()),
Expand Down
13 changes: 12 additions & 1 deletion samtranslator/model/eventsources/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ class PullEventSource(ResourceMacro):
'BatchSize': PropertyType(False, is_type(int)),
'StartingPosition': PropertyType(False, is_str()),
'Enabled': PropertyType(False, is_type(bool)),
'MaximumBatchingWindowInSeconds': PropertyType(False, is_type(int))
'MaximumBatchingWindowInSeconds': PropertyType(False, is_type(int)),
'MaximumRetryAttempts': PropertyType(False, is_type(int)),
'BisectBatchOnFunctionError': PropertyType(False, is_type(bool)),
'MaximumRecordAgeInSeconds': PropertyType(False, is_type(int)),
'DestinationConfig': PropertyType(False, is_type(dict)),
'ParallelizationFactor': PropertyType(False, is_type(int))
}

def get_policy_arn(self):
Expand Down Expand Up @@ -66,6 +71,12 @@ def to_cloudformation(self, **kwargs):
lambda_eventsourcemapping.BatchSize = self.BatchSize
lambda_eventsourcemapping.Enabled = self.Enabled
lambda_eventsourcemapping.MaximumBatchingWindowInSeconds = self.MaximumBatchingWindowInSeconds
lambda_eventsourcemapping.MaximumRetryAttempts = self.MaximumRetryAttempts
lambda_eventsourcemapping.BisectBatchOnFunctionError = self.BisectBatchOnFunctionError
lambda_eventsourcemapping.MaximumRecordAgeInSeconds = self.MaximumRecordAgeInSeconds
lambda_eventsourcemapping.DestinationConfig = self.DestinationConfig
lambda_eventsourcemapping.ParallelizationFactor = self.ParallelizationFactor

if 'Condition' in function.resource_attributes:
lambda_eventsourcemapping.set_resource_attribute('Condition', function.resource_attributes['Condition'])

Expand Down
2 changes: 2 additions & 0 deletions samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class CloudWatchEvent(PushEventSource):
resource_type = 'CloudWatchEvent'
principal = 'events.amazonaws.com'
property_types = {
'EventBusName': PropertyType(False, is_str()),
'Pattern': PropertyType(False, is_type(dict)),
'Input': PropertyType(False, is_str()),
'InputPath': PropertyType(False, is_str())
Expand All @@ -164,6 +165,7 @@ def to_cloudformation(self, **kwargs):
resources = []

events_rule = EventsRule(self.logical_id)
events_rule.EventBusName = self.EventBusName
events_rule.EventPattern = self.Pattern
events_rule.Targets = [self._construct_target(function)]
if CONDITION in function.resource_attributes:
Expand Down
8 changes: 7 additions & 1 deletion samtranslator/model/lambda_.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class LambdaAlias(Resource):
'Description': PropertyType(False, is_str()),
'Name': PropertyType(False, is_str()),
'FunctionName': PropertyType(True, one_of(is_str(), is_type(dict))),
'FunctionVersion': PropertyType(True, one_of(is_str(), is_type(dict)))
'FunctionVersion': PropertyType(True, one_of(is_str(), is_type(dict))),
'ProvisionedConcurrencyConfig': PropertyType(False, is_type(dict))
}

runtime_attrs = {
Expand All @@ -66,6 +67,11 @@ class LambdaEventSourceMapping(Resource):
'EventSourceArn': PropertyType(True, is_str()),
'FunctionName': PropertyType(True, is_str()),
'MaximumBatchingWindowInSeconds': PropertyType(False, is_type(int)),
'MaximumRetryAttempts': PropertyType(False, is_type(int)),
'BisectBatchOnFunctionError': PropertyType(False, is_type(bool)),
'MaximumRecordAgeInSeconds': PropertyType(False, is_type(int)),
'DestinationConfig': PropertyType(False, is_type(dict)),
'ParallelizationFactor': PropertyType(False, is_type(int)),
'StartingPosition': PropertyType(False, is_str())
}

Expand Down
10 changes: 9 additions & 1 deletion samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class SamFunction(SamResourceMacro):

# Intrinsic functions in value of Alias property are not supported, yet
'AutoPublishAlias': PropertyType(False, one_of(is_str())),
'VersionDescription': PropertyType(False, is_str())
'VersionDescription': PropertyType(False, is_str()),
'ProvisionedConcurrencyConfig': PropertyType(False, is_type(dict)),
}
event_resolver = ResourceTypeResolver(samtranslator.model.eventsources, samtranslator.model.eventsources.pull,
samtranslator.model.eventsources.push,
Expand Down Expand Up @@ -96,6 +97,11 @@ def to_cloudformation(self, **kwargs):
lambda_function = self._construct_lambda_function()
resources.append(lambda_function)

if self.ProvisionedConcurrencyConfig:
if not self.AutoPublishAlias:
raise InvalidResourceException(self.logical_id, "To set ProvisionedConcurrencyConfig "
"AutoPublishALias must be defined on the function")

lambda_alias = None
if self.AutoPublishAlias:
alias_name = self._get_resolved_alias_name("AutoPublishAlias", self.AutoPublishAlias, intrinsics_resolver)
Expand Down Expand Up @@ -415,6 +421,8 @@ def _construct_alias(self, name, function, version):
alias.Name = name
alias.FunctionName = function.get_runtime_attr('name')
alias.FunctionVersion = version.get_runtime_attr("version")
if self.ProvisionedConcurrencyConfig:
alias.ProvisionedConcurrencyConfig = self.ProvisionedConcurrencyConfig

return alias

Expand Down
3 changes: 2 additions & 1 deletion samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class Globals(object):
"Layers",
"DeploymentPreference",
"PermissionsBoundary",
"ReservedConcurrentExecutions"
"ReservedConcurrentExecutions",
"ProvisionedConcurrencyConfig"
],

# Everything except
Expand Down
3 changes: 3 additions & 0 deletions samtranslator/validator/sam_schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@
"AWS::Serverless::Function.CloudWatchEventEvent": {
"additionalProperties": false,
"properties": {
"EventBusName": {
"type": "string"
},
"Input": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions tests/translator/input/cloudwatchevent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Resources:
OnTerminate:
Type: CloudWatchEvent
Properties:
EventBusName: ExternalEventBridge
Pattern:
detail:
state:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Parameters:
FnName:
Type: String
ProvisionedConcurrency:
Type: String
Default: 10
EnableAliasProvisionedConcurrency:
Type: String
AllowedValues:
- true
- false
Default: true
Conditions:
AliasProvisionedConcurrencyEnabled: !Equals [!Ref EnableAliasProvisionedConcurrency, true]
Resources:
MinimalFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python2.7
DeploymentPreference:
Type: Linear10PercentEvery3Minutes
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: !If [AliasProvisionedConcurrencyEnabled, ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency, !Ref 'AWS::NoValue']
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
Parameters:
FnName:
Type: String
ProvisionedConcurrency:
Type: String
Default: 10
EnableAliasProvisionedConcurrency:
Type: String
AllowedValues:
- true
- false
Default: true
Conditions:
AliasProvisionedConcurrencyEnabled: !Equals [!Ref EnableAliasProvisionedConcurrency, true]
Resources:
MinimalFunction:
Type: 'AWS::Serverless::Function'
Expand All @@ -7,4 +21,6 @@ Resources:
Runtime: python2.7
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery3Minutes
Type: Linear10PercentEvery3Minutes
ProvisionedConcurrencyConfig:
ProvisionedConcurrentExecutions: !If [AliasProvisionedConcurrencyEnabled, !Ref ProvisionedConcurrency, !Ref 'AWS::NoValue']
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: EventSourceMapping example with MaximumBatchingWindowInSeconds property

Parameters:
MyBatchingWindowParam:
Expand All @@ -23,6 +22,9 @@ Resources:
}
}
Runtime: nodejs8.10
Policies:
- SQSSendMessagePolicy:
QueueName: !GetAtt MySqsQueue.QueueName
Events:
Stream:
Type: Kinesis
Expand All @@ -42,7 +44,14 @@ Resources:
Stream: !GetAtt DynamoDBTable.StreamArn
BatchSize: 100
MaximumBatchingWindowInSeconds: !Ref MyBatchingWindowParam
ParallelizationFactor: 8
MaximumRetryAttempts: 100
BisectBatchOnFunctionError: true
MaximumRecordAgeInSeconds: 86400
StartingPosition: TRIM_HORIZON
DestinationConfig:
OnFailure:
Destination: !GetAtt MySqsQueue.Arn

KinesisStream:
Type: AWS::Kinesis::Stream
Expand All @@ -66,4 +75,7 @@ Resources:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
StreamSpecification:
StreamViewType: NEW_IMAGE
StreamViewType: NEW_IMAGE

MySqsQueue:
Type: AWS::SQS::Queue
1 change: 1 addition & 0 deletions tests/translator/output/aws-cn/cloudwatchevent.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
]
}
},
"EventBusName": "ExternalEventBridge",
"Targets": [
{
"Id": "TriggeredFunctionOnTerminateLambdaTarget",
Expand Down
Loading