-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sandbox): create project template for AWS Lambda in Python (ARCH…
…-352) (#2936)
- Loading branch information
1 parent
e391dc8
commit b38dc22
Showing
19 changed files
with
596 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file is auto generated by SAM CLI build command | ||
|
||
[function_build_definitions.a4887bcd-4b8c-43ca-a4d1-9fe4d156fee4] | ||
packagetype = "Image" | ||
functions = ["HelloWorldFunction"] | ||
|
||
[function_build_definitions.a4887bcd-4b8c-43ca-a4d1-9fe4d156fee4.metadata] | ||
Dockerfile = "Dockerfile" | ||
DockerContext = "/workspaces/sage-monorepo/apps/sandbox/lambda-python" | ||
DockerTag = "python3.13-v1" | ||
|
||
[layer_build_definitions] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
|
||
# Created by https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode | ||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
# .nfs files are created when an open file is removed but is still being accessed | ||
.nfs* | ||
|
||
### OSX ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
### PyCharm ### | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff: | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/dictionaries | ||
|
||
# Sensitive or high-churn files: | ||
.idea/**/dataSources/ | ||
.idea/**/dataSources.ids | ||
.idea/**/dataSources.xml | ||
.idea/**/dataSources.local.xml | ||
.idea/**/sqlDataSources.xml | ||
.idea/**/dynamic.xml | ||
.idea/**/uiDesigner.xml | ||
|
||
# Gradle: | ||
.idea/**/gradle.xml | ||
.idea/**/libraries | ||
|
||
# CMake | ||
cmake-build-debug/ | ||
|
||
# Mongo Explorer plugin: | ||
.idea/**/mongoSettings.xml | ||
|
||
## File-based project format: | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
|
||
# Ruby plugin and RubyMine | ||
/.rakeTasks | ||
|
||
# Crashlytics plugin (for Android Studio and IntelliJ) | ||
com_crashlytics_export_strings.xml | ||
crashlytics.properties | ||
crashlytics-build.properties | ||
fabric.properties | ||
|
||
### PyCharm Patch ### | ||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 | ||
|
||
# *.iml | ||
# modules.xml | ||
# .idea/misc.xml | ||
# *.ipr | ||
|
||
# Sonarlint plugin | ||
.idea/sonarlint | ||
|
||
### Python ### | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
.pytest_cache/ | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule.* | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
### VisualStudioCode ### | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
.history | ||
|
||
### Windows ### | ||
# Windows thumbnail cache files | ||
Thumbs.db | ||
ehthumbs.db | ||
ehthumbs_vista.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# Build folder | ||
|
||
*/build/* | ||
|
||
# End of https://www.gitignore.io/api/osx,linux,python,windows,pycharm,visualstudiocode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM public.ecr.aws/lambda/python:3.13 | ||
|
||
COPY hello_world/app.py requirements.txt ${LAMBDA_TASK_ROOT}/ | ||
|
||
RUN python3.13 -m pip install --no-cache-dir -r requirements.txt -t . | ||
|
||
# Command can be overwritten by providing a different command in the template directly. | ||
CMD ["app.lambda_handler"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Sandbox Lambda Python | ||
|
||
## Build the project | ||
|
||
```console | ||
nx build sandbox-lambda-python | ||
``` | ||
|
||
## Build the Docker image of the Lambda function | ||
|
||
```console | ||
nx build-image sandbox-lambda-python | ||
``` | ||
|
||
## Start the Lambda function locally with Docker Compose | ||
|
||
Starts the Lambda function in the foreground, allowing you to view logs and interact with it | ||
directly. | ||
|
||
```console | ||
nx serve sandbox-lambda-python | ||
``` | ||
|
||
Starts the Lambda function in detached mode, running it in the background. This is useful if you | ||
want to continue using the terminal for other tasks while the function runs. | ||
|
||
```console | ||
nx serve-detach sandbox-lambda-python | ||
``` | ||
|
||
## Invoke the Lambda function locally | ||
|
||
To invoke the Lambda function after starting it locally, use the following command: | ||
|
||
```console | ||
nx run sandbox-lambda-python:invoke --event <path-to-json-file> | ||
``` | ||
|
||
Replace `<path-to-json-file>` with the path to your JSON file containing the event payload relative | ||
to the location of the project folder. For example, if your event payload is stored in a file | ||
located at `events/event.json` relative to the project folder: | ||
|
||
```console | ||
nx run sandbox-lambda-python:invoke --event events/event.json | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"body": "{\"message\": \"hello world\"}", | ||
"resource": "/hello", | ||
"path": "/hello", | ||
"httpMethod": "GET", | ||
"isBase64Encoded": false, | ||
"queryStringParameters": { | ||
"foo": "bar" | ||
}, | ||
"pathParameters": { | ||
"proxy": "/path/to/resource" | ||
}, | ||
"stageVariables": { | ||
"baz": "qux" | ||
}, | ||
"headers": { | ||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", | ||
"Accept-Encoding": "gzip, deflate, sdch", | ||
"Accept-Language": "en-US,en;q=0.8", | ||
"Cache-Control": "max-age=0", | ||
"CloudFront-Forwarded-Proto": "https", | ||
"CloudFront-Is-Desktop-Viewer": "true", | ||
"CloudFront-Is-Mobile-Viewer": "false", | ||
"CloudFront-Is-SmartTV-Viewer": "false", | ||
"CloudFront-Is-Tablet-Viewer": "false", | ||
"CloudFront-Viewer-Country": "US", | ||
"Host": "1234567890.execute-api.us-east-1.amazonaws.com", | ||
"Upgrade-Insecure-Requests": "1", | ||
"User-Agent": "Custom User Agent String", | ||
"Via": "1.1 08f323deadbeefa7af34d5feb414ce27.cloudfront.net (CloudFront)", | ||
"X-Amz-Cf-Id": "cDehVQoZnx43VYQb9j2-nvCh-9z396Uhbp027Y2JvkCPNLmGJHqlaA==", | ||
"X-Forwarded-For": "127.0.0.1, 127.0.0.2", | ||
"X-Forwarded-Port": "443", | ||
"X-Forwarded-Proto": "https" | ||
}, | ||
"requestContext": { | ||
"accountId": "123456789012", | ||
"resourceId": "123456", | ||
"stage": "prod", | ||
"requestId": "c6af9ac6-7b61-11e6-9a41-93e8deadbeef", | ||
"requestTime": "09/Apr/2015:12:34:56 +0000", | ||
"requestTimeEpoch": 1428582896000, | ||
"identity": { | ||
"cognitoIdentityPoolId": null, | ||
"accountId": null, | ||
"cognitoIdentityId": null, | ||
"caller": null, | ||
"accessKey": null, | ||
"sourceIp": "127.0.0.1", | ||
"cognitoAuthenticationType": null, | ||
"cognitoAuthenticationProvider": null, | ||
"userArn": null, | ||
"userAgent": "Custom User Agent String", | ||
"user": null | ||
}, | ||
"path": "/prod/hello", | ||
"resourcePath": "/hello", | ||
"httpMethod": "POST", | ||
"apiId": "1234567890", | ||
"protocol": "HTTP/1.1" | ||
} | ||
} |
Empty file.
Oops, something went wrong.