-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCFN-CR-PythonLambdaLayer-SampleUsage.yaml
128 lines (118 loc) · 3.71 KB
/
CFN-CR-PythonLambdaLayer-SampleUsage.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
AWSTemplateFormatVersion: '2010-09-09'
Description: >-
This stack will demo the Layer Builder CFN CR, with few example Layer
Also used for testing...
Metadata:
Author: KissT
Project: CFN-CR-PythonLambdaLayer
SourceCode: https://github.com/kisst/CFN-CR-PythonLambdaLayer
Resources:
EmptyLambdaLayer:
Properties:
ServiceToken:
Fn::ImportValue: !Sub "cfn:lambdalayer:${AWS::Region}:arn"
Name: test-gracefull-exit
Region: !Ref "AWS::Region"
Type: Custom::LayerBuilder
Boto3LambdaLayer:
Properties:
ServiceToken:
Fn::ImportValue: !Sub "cfn:lambdalayer:${AWS::Region}:arn"
Name: boto3-latest
Region: !Ref "AWS::Region"
requirements:
- boto3
Type: Custom::LayerBuilder
TropoLambdaLayer:
Properties:
ServiceToken:
Fn::ImportValue: !Sub "cfn:lambdalayer:${AWS::Region}:arn"
Name: cfn-account-policy
Region: !Ref "AWS::Region"
requirements:
- "troposphere>2.3.0"
- "awacs==0.7.2"
Type: Custom::LayerBuilder
InlineCodeLambdaLayer:
Properties:
ServiceToken:
Fn::ImportValue: !Sub "cfn:lambdalayer:${AWS::Region}:arn"
Name: inline-code-only
Region: !Ref "AWS::Region"
filename: eratosthenes.py
filecontent:
Fn::Base64: !Sub |
def sieve(n):
# https://wikipedia.org/wiki/Sieve_of_Eratosthenes
return sorted(
set(range(2,n+1)).difference(
set((p * f) \
for p in range(2,int(n**0.5) + 2) \
for f in range(2,(n//p)+1))
)
)
Type: Custom::LayerBuilder
InlineCodeWithPipPackageLambdaLayer:
Properties:
ServiceToken:
Fn::ImportValue: !Sub "cfn:lambdalayer:${AWS::Region}:arn"
Name: inline-code-and-requirements
Region: !Ref "AWS::Region"
requirements:
- python-whois
filename: module.py
filecontent:
Fn::Base64: !Sub |
from whois import whois
def examine(domain):
return whois(domain)
Type: Custom::LayerBuilder
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: AllowLogs
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: 'arn:aws:logs:*:*:*'
DemoLambdaFuntion:
Type: 'AWS::Lambda::Function'
Properties:
Description: 'Show lib version from the layers'
Code:
ZipFile: |
import troposphere
import boto3
from lambdalayer.module import examine
from lambdalayer.eratosthenes import sieve
def lambda_handler(event, context):
print("Tropo version: {}".format(troposphere.__version__))
print("Boto3 version: {}".format(boto3.__version__))
print("Sieve of Eratosthenes from 10: {}".format(sieve(10)))
print("WhoIs example.com: {}".format(examine('example.com')))
Handler: index.lambda_handler
Runtime: python3.7
Timeout: 60
Role: !GetAtt LambdaExecutionRole.Arn
Layers:
- !GetAtt Boto3LambdaLayer.Arn
- !GetAtt TropoLambdaLayer.Arn
- !GetAtt InlineCodeWithPipPackageLambdaLayer.Arn
- !GetAtt InlineCodeLambdaLayer.Arn