Skip to content

ServerlessOpsIO/PhotoOps

Repository files navigation

PhotoOps

PhotoOpsAI central application platform

.
├── LICENSE
├── Makefile
├── Pipfile
├── README.md
├── events
├── pytest.ini
├── src
│   ├── common
│   │   ├── common
│   │   │   └── __init__.py
│   │   └── setup.py
│   └── handlers
├── template.yaml
└── tests
    ├── conftest.py
    ├── integration
    │   ├── __init__.py
    │   └── src
    │       ├── __init__.py
    │       └── handlers
    │           └── __init__.py
    └── unit
        ├── __init__.py
        └── src
            ├── __init__.py
            └── handlers
                └── __init__.py

References

Requirements

Managing Mock Data & Schemas

  1. Obtain or write sample data.
  2. Use Python genson to generate a schema. Adjust as necessary.
  3. Use json2models -s nested --datetime --max-strings-literals 0 -f dataclasses -m ClassName <json_file> to generate dataclass.
  4. Add test to tests/unit/data to ensure data, schema, and dataclass.

Setup process

Local development

Invoking function locally using a local sample payload

sam local invoke <FUNCTION_NAME> --event events/<FUNCTION_NAME>-<EVENT_SOURCE>.json

Invoking function locally through local API Gateway

sam local start-api

If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function http://localhost:3000/hello

SAM CLI is used to emulate both Lambda and API Gateway locally and uses our template.yaml to understand how to bootstrap this environment (runtime, where the source code is, etc.) - The following excerpt is what the CLI will read in order to initialize an API and its routes:

...
Events:
  HelloWorld:
    Type: Api
    Properties:
      Path: /hello
      Method: get

Packaging and deployment

To package and deploy this service run the command below.

$ make deploy

This will:

  • Create an artifact deployment S3 bucket
  • Bundle application dependencies
  • Package the code and dependencies
  • Upload code to S3.
  • Deploy code via Cloudformation

Fetch, tail, and filter Lambda function logs

To simplify troubleshooting, SAM CLI has a command called sam logs. sam logs lets you fetch logs generated by your Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug.

NOTE: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.

sam logs -n <FUNCTION_NAME> --stack-name PhotoOps --tail

You can find more information and examples about filtering Lambda function logs in the SAM CLI Documentation.

Testing

Next, we install test dependencies and we run pytest against our tests folder to run our initial unit tests:

pip install pytest pytest-mock --user
python -m pytest tests/ -v

Cleanup

In order to delete our Serverless Application recently deployed you can use the following AWS CLI Command:

aws cloudformation delete-stack --stack-name PhotoOps

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published