LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Handler: index.handler
Description: HelloWorld AppConfig Function
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: python3.8
Layers:
- !FindInMap [ RegionMap, !Ref "AWS::Region" , appconfiglayerarn ]
Timeout: 60
Code:
ZipFile: !Sub |
import json
import urllib.request
def handler(event, context):
num_exclamations = get_configured_number_of("ExclamationPoints", 1)
return f'Hello world{"!" * num_exclamations}'
def get_configured_number_of(configuration_type, default):
try:
url = f'http://localhost:2772/applications/${ServiceName}/environments/dev/configurations/' + configuration_type
config = json.loads(urllib.request.urlopen(url).read())
if config.get("enable" + configuration_type, False):
return config.get("numberOf" + configuration_type, default)
else:
return default
except:
return default
LambdaExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: LambdaExecutionRole
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- appconfig:ListTagsForResource
- appconfig:GetEnvironment
- appconfig:GetDeploymentStrategy
- appconfig:GetHostedConfigurationVersion
- appconfig:GetDeployment
- appconfig:GetConfiguration
- appconfig:GetApplication
- appconfig:GetConfigurationProfile
Resource:
- !Sub "arn:aws:appconfig:${AWS::Region}:${AWS::AccountId}:application/${AppConfig}"
- !Sub "arn:aws:appconfig:${AWS::Region}:${AWS::AccountId}:application/${AppConfig}/*"
Parameters
These are the input parameters for this template. All of these parameters must be supplied for this template to be deployed.