File: custom_lambda.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (84 lines) | stat: -rw-r--r-- 3,233 bytes parent folder | download | duplicates (2)
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
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/walkthrough-custom-resources-lambda-lookup-amiids.html


def get_template(lambda_code):
    return {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Description": "Sample template using Custom Resource",
        "Resources": {
            "CustomInfo": {
                "Type": "Custom::Info",
                "Properties": {
                    "ServiceToken": {"Fn::GetAtt": ["InfoFunction", "Arn"]},
                    "Region": {"Ref": "AWS::Region"},
                    "MyProperty": "stuff",
                },
            },
            "InfoFunction": {
                "Type": "AWS::Lambda::Function",
                "Properties": {
                    "Code": {
                        "ZipFile": {"Fn::Join": ["\n", lambda_code.splitlines()]},
                    },
                    "Handler": "index.lambda_handler",
                    "Role": {"Fn::GetAtt": ["LambdaExecutionRole", "Arn"]},
                    "Runtime": "python3.8",
                    "Timeout": "30",
                },
            },
            "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": "root",
                            "PolicyDocument": {
                                "Version": "2012-10-17",
                                "Statement": [
                                    {
                                        "Effect": "Allow",
                                        "Action": [
                                            "logs:CreateLogGroup",
                                            "logs:CreateLogStream",
                                            "logs:PutLogEvents",
                                        ],
                                        "Resource": "arn:aws:logs:*:*:*",
                                    }
                                ],
                            },
                        }
                    ],
                },
            },
        },
        "Outputs": {
            "infokey": {
                "Description": "A very important value",
                "Value": {"Fn::GetAtt": ["CustomInfo", "info_value"]},
            }
        },
    }


def get_template_for_unknown_lambda():
    return {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Description": "Sample template using Custom Resource pointing to unknown Function",
        "Resources": {
            "CustomInfo": {
                "Type": "Custom::Info",
                "Properties": {"ServiceToken": {"Fn::GetAtt": ["InfoFunction", "Arn"]}},
            },
        },
    }