@DrEigelb, , :
# This stack contains basic components for custom resource which allows you to
# configure lambda concurrency limit during stack creation. It contains lambda
# function and a role for the lambda. To start you should deploy this stack to
# the region and the account where you want to use it, then add custom resource
# with two parameters (`LambdaArn` and `ReservedConcurrentExecutions`) into you
# stack:
#
# LambdaConfigurator:
# Type: Custom::LambdaConfigurator
# Properties:
# ServiceToken: !ImportValue Custom--LambdaConfiguratorFunction--Arn
# Region: !Ref "AWS::Region"
# LambdaArn: !GetAtt TargetLambda.Arn
# ReservedConcurrentExecutions: 10
#
Description: Holds custom resource for changing configuration of lambda
AWSTemplateFormatVersion: '2010-09-09'
Resources:
LambdaConfiguratorFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
import re
import boto3
import cfnresponse
def handler(event, context):
try:
if event['RequestType'] == 'Delete':
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
return
function_name = event['ResourceProperties']['LambdaArn']
concurrency = int(event['ResourceProperties']['ReservedConcurrentExecutions'])
print('FunctionName: {}, ReservedConcurrentExecutions: {}'.format(function_name, concurrency))
client = boto3.client('lambda')
client.put_function_concurrency(FunctionName=function_name, ReservedConcurrentExecutions=concurrency)
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
except Exception as e:
err = '{}: {}'.format(e.__class__.__name__, str(e))
print(err)
cfnresponse.send(event, context, cfnresponse.FAILED, {'Reason': err})
Handler: index.handler
Runtime: python3.6
Timeout: 30
Role:
Fn::GetAtt: LambdaConfiguratorLambdaExecutionRole.Arn
LambdaConfiguratorLambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
Policies:
- PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*
- Effect: Allow
Action:
- lambda:*
Resource: "*"
Outputs:
LambdaConfiguratorFunctionArnOutput:
Value: !GetAtt LambdaConfiguratorFunction.Arn
Export:
Name: Custom--LambdaConfiguratorFunction--Arn
source
share