-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.sh
More file actions
executable file
·117 lines (93 loc) · 2.65 KB
/
generate.sh
File metadata and controls
executable file
·117 lines (93 loc) · 2.65 KB
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
#!/bin/bash
# filepath: create_lambda.sh
if [ $# -ne 1 ]; then
echo "Usage: $0 <function-name>"
exit 1
fi
FUNCTION_NAME=$1
BASE_DIR="functions/$FUNCTION_NAME"
APP_DIR="$BASE_DIR/app"
# Create directories
mkdir -p "$APP_DIR"
# Create README.md (empty)
touch "$BASE_DIR/README.md"
# Create app.py with handler
cat > "$APP_DIR/main.py" << EOF
import json
import os
from ldap3 import Server, Connection, ALL, SUBTREE
def handler(event, context):
"""
Lambda handler for $FUNCTION_NAME function
Args:
event: Lambda event
context: Lambda context
Returns:
Lambda response
"""
try:
# Your function logic here
return {
'statusCode': 200,
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
'body': json.dumps({'message': 'Success from $FUNCTION_NAME'})
}
except Exception as e:
print(f"Error: {str(e)}")
return {
'statusCode': 500,
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
'body': json.dumps({'error': str(e)})
}
EOF
# Create setup.py
cat > "$BASE_DIR/setup.py" << EOF
"""Package setup."""
import os
import setuptools
# Requirements
requirements = [
"ldap3==2.9.1",
]
# Development Requirements
requirements_dev = ["pytest==7.4.0", "black==23.9.1"]
with open("./README.md", "r") as f:
long_description = f.read()
setuptools.setup(
name="$FUNCTION_NAME",
author="LEAP-AD",
author_email="core-devops@lftechnology.com",
description="Lambda functions for helipad for active directory",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/koiralaprt/admgmt/functions/$FUNCTION_NAME",
packages=setuptools.find_packages(),
install_requires=requirements,
extras_require={"dev": requirements_dev},
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
)
EOF
# Create Dockerfile
cat > "$BASE_DIR/Dockerfile" << EOF
FROM python:3.12-slim AS base
FROM base AS main
WORKDIR /source
COPY ["app", "./app"]
COPY ["setup.py", "README.md", "./"]
RUN apt-get --allow-releaseinfo-change update -y \\
&& apt-get install -y git libpq-dev build-essential \\
&& pip install . \\
&& pip install awslambdaric
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "app.main.handler" ]
EOF
echo "Lambda function structure for '$FUNCTION_NAME' created successfully in $BASE_DIR"