Is there a way to test an application deployed with Zappa? - python

I have created a Django application which is deployed to AWS using Zappa in a CI/CD pipeline using the following commands:
- zappa update $ENVIRONMENT
- zappa manage $ENVIRONMENT "collectstatic --noinput"
- zappa manage $ENVIRONMENT "migrate"
However I want to add a test step to the CI/CD pipeline that would test the application much like in a way that I would test the application locally using the Django command:
python manage.py test
Is there a way to issue a zappa command to make run the "python manage.py test"? Do you have any suggestion?

Here is the docs that have a docker setup that you can use for local testing (Docs here)
Also, this post from Ian Whitestone(a core Zappa contributor) uses the official AWS docker image for the same job. And he has given one example for local testing also (Blog post)

Related

Changes are not being deployed to AWS console

I am deploying changes to AWS console throuhg the command
cdk deploy --all
Previously it worked well and created the stack on AWS console but now after creating another stack when I tried to run the same command cdk deploy all rather than deploying code to AWS it shows just following four statements
Usage:
cdk [-vbo] [--toc] [--notransition] [--logo=<logo>] [--theme=<theme>] [--custom-css=<cssfile>] FILE
cdk --install-theme=<theme>
cdk --default-theme=<theme>
cdk --generate=<name>
Something changed in your environment and now cdk is pointing to the Courseware Development Kit instead of the aws-cdk.
You can confirm this by studying the output of which cdk.
To fix this, uninstall Courseware Development Kit or create a shell alias for it (after putting it further down in your $PATH).
Also, cdk deploy all is not the right command - you're looking for cdk deploy --all.

Can you call AWS CDK in python without CLI?

Is it possible to run the AWS CDK lifecycle directly in python (or any other language), without using the cli? e.g.
app.py
app = cdk.App()
Stack(app, ..)
app.synth()
app.deploy()
run python
python app.py //instead of cdk deploy...
this could be useful to prepare temporary test scenarios.
What's possible as of today:
Programatically synth templates without cdk synth?
Yes. CDK's testing constructs work this way. Tests assert against a programatically synth-ed template.
template = Template.from_stack(processor_stack)
template.resource_count_is("AWS::SNS::Subscription", 1)
Programatically deploy apps without cdk deploy?
Not in the way the OP describes, but you can get close with the CDK's CI/CD constructs. The CDK Pipelines construct synths and deploys CDK apps programatically. Build a pipeline that builds and tears-down a testing environment on each push to your remote repository. Alternatively, a standalone CodeBuild Project can be used with commands to cdk deploy an app and perform tests when triggered by an event.
Also worth mentioning is cdk watch for rapid local development iterations. It automatically deploys incremental changes as you code.

Deploy FastAPI microservice in Kubernetes via OpenFaaS

I have a big application structured with FastAPI (with many routers), that runs in AWS Lambda. I want to migrate it to a container inside Kubernetes. From my research, OpenFaaS is a great solution.
However I can't find documentation about how to do this.
Does anyone has references or a better solution?
If you are using the python or Ruby
You can create the docker file and use it for creating the docker images and simply deploy it on Kubernetes.
FROM ruby:2.7-alpine3.11
WORKDIR /home/app
COPY . .
RUN bundle install
CMD ["ruby", "main.rb"]
For OpenFass they have provided good labs with documentation to create the Async function etc.
Labs : https://github.com/openfaas/workshop
If you are looking for examples you can check out the official repo only : https://github.com/openfaas/faas/tree/master/sample-functions
Extra
There is also another good option Knative or Kubeless
You can find the python Kubeless example and CI/CD example : https://github.com/harsh4870/kubeless-kubernetes-ci-cd
Try use a template to build an upstream FastAPI application as an OpenFAAS function. This will create a docker image you can run and deploy in your Kubernetes cluster.
You can see how to do so in the following github repo

Python pipeline error when deploying to EC2 setuptools_rust

Hello I'm having this problem when trying to deploy a django application to aws, the app runs perfectly locally but when trying to deploy to aws this error shows up.
like this
I tried to install that manually, but it doesn't work that way.
If the docker version for your deployment runner is 20.x - it's probably this https://github.com/docker/compose/issues/8105
Try pinning the deploy docker version to 19.03.13ce-1

How to deploy a single python script with gitlab-ci?

I created a bot in python and wanted to auto deploy it with every new release on my personal gitlab runner.
I have the following .gilab-ci.yml and didn't found a solution for my problem, because the gitlab runner seems to close it every time.
image: python:3.7.4
before_script:
- pip install -r requirements.txt
deploy_prod:
stage: deploy
script:
- setsid nohup python __main__.py &
environment:
name: production
when: manual
I also tried python __main__.py &.
GitLab CI isn't really made to be used for hosting applications as you are trying to do.
In the advanced configurations options for GitLab CI, there are ways to modify the timeouts, you could try to hijack them but it really isn't what it is meant for.
GitLab CI is meant to execute short term operations to build your code and deploy applications to other servers, not for hosting long running applications.

Categories