1660488660
讓我們看看如何配置在 EC2 實例上運行的容器化 Django 應用程序以將日誌發送到 Amazon CloudWatch。
步驟:
首先創建一個新的 IAM 角色並附加CloudWatchAgentServerPolicy策略以供 Docker 守護程序使用,以便寫入 CloudWatch。
從IAM 控制台,選擇“角色”並單擊“創建角色”。選擇“常見用例”下的“EC2”服務:
單擊下一步按鈕。
在權限頁面上,搜索“CloudWatchAgentServerPolicy”策略並選中復選框以附加它:
單擊下一步幾次。在審核頁面上,輸入角色名稱——即CloudWatchAgentRole
——然後創建角色。
要將角色附加到 EC2 實例,請導航到EC2 儀表板並選擇實例。單擊“操作”下拉菜單,選擇“實例設置”,然後單擊“附加/替換 IAM 角色”:
搜索並選擇您剛剛創建的 IAM 角色,然後單擊“應用”。
您還可以從命令行附加角色,如下所示:
$ aws ec2 associate-iam-instance-profile \ --instance-id <YOUR_INSTANCE_ID> \ --iam-instance-profile Name=CloudWatchAgentRole
現在 Docker 守護程序有權寫入 CloudWatch,讓我們創建一個要寫入的日誌組。在CloudWatch 控制台中,創建一個新的日誌組。也向該新創建的組添加新的日誌流。
通過 SSH 連接到 EC2 實例並直接從 S3 下載並安裝 CloudWatch Logs 代理。
例子:
# download
$ curl https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
# install
$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
由於 Docker 容器將日誌發送到 stdout 和 stderr 輸出流,因此您需要配置 Django 日誌記錄以通過StreamHandler將所有內容記錄到 stderr 。
例如:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler'
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
},
},
}
最後,我們可以在單個容器中使用 Docker 的awslogs日誌記錄驅動程序。
例如:
version: "3.8"
services:
api:
build: ./project
command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --log-level=debug
logging:
driver: "awslogs"
options:
awslogs-region: "us-east-1"
awslogs-group: "your-log-group"
awslogs-stream: "your-log-stream"
不使用撰寫?假設您已經構建並標記了圖像,請像這樣啟動容器:
$ docker run \
--log-driver="awslogs" \
--log-opt awslogs-region="use-east-1" \
--log-opt awslogs-group="your-log-group" \
--log-opt awslogs-stream="your-log-group" \
your-image-tag
1620177818
Welcome to my blog , hey everyone in this article you learn how to customize the Django app and view in the article you will know how to register and unregister models from the admin view how to add filtering how to add a custom input field, and a button that triggers an action on all objects and even how to change the look of your app and page using the Django suit package let’s get started.
#django #create super user django #customize django admin dashboard #django admin #django admin custom field display #django admin customization #django admin full customization #django admin interface #django admin register all models #django customization
1660488660
讓我們看看如何配置在 EC2 實例上運行的容器化 Django 應用程序以將日誌發送到 Amazon CloudWatch。
步驟:
首先創建一個新的 IAM 角色並附加CloudWatchAgentServerPolicy策略以供 Docker 守護程序使用,以便寫入 CloudWatch。
從IAM 控制台,選擇“角色”並單擊“創建角色”。選擇“常見用例”下的“EC2”服務:
單擊下一步按鈕。
在權限頁面上,搜索“CloudWatchAgentServerPolicy”策略並選中復選框以附加它:
單擊下一步幾次。在審核頁面上,輸入角色名稱——即CloudWatchAgentRole
——然後創建角色。
要將角色附加到 EC2 實例,請導航到EC2 儀表板並選擇實例。單擊“操作”下拉菜單,選擇“實例設置”,然後單擊“附加/替換 IAM 角色”:
搜索並選擇您剛剛創建的 IAM 角色,然後單擊“應用”。
您還可以從命令行附加角色,如下所示:
$ aws ec2 associate-iam-instance-profile \ --instance-id <YOUR_INSTANCE_ID> \ --iam-instance-profile Name=CloudWatchAgentRole
現在 Docker 守護程序有權寫入 CloudWatch,讓我們創建一個要寫入的日誌組。在CloudWatch 控制台中,創建一個新的日誌組。也向該新創建的組添加新的日誌流。
通過 SSH 連接到 EC2 實例並直接從 S3 下載並安裝 CloudWatch Logs 代理。
例子:
# download
$ curl https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
# install
$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
由於 Docker 容器將日誌發送到 stdout 和 stderr 輸出流,因此您需要配置 Django 日誌記錄以通過StreamHandler將所有內容記錄到 stderr 。
例如:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler'
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
},
},
}
最後,我們可以在單個容器中使用 Docker 的awslogs日誌記錄驅動程序。
例如:
version: "3.8"
services:
api:
build: ./project
command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --log-level=debug
logging:
driver: "awslogs"
options:
awslogs-region: "us-east-1"
awslogs-group: "your-log-group"
awslogs-stream: "your-log-stream"
不使用撰寫?假設您已經構建並標記了圖像,請像這樣啟動容器:
$ docker run \
--log-driver="awslogs" \
--log-opt awslogs-region="use-east-1" \
--log-opt awslogs-group="your-log-group" \
--log-opt awslogs-stream="your-log-group" \
your-image-tag
1620185280
Welcome to my blog, hey everyone in this article we are going to be working with queries in Django so for any web app that you build your going to want to write a query so you can retrieve information from your database so in this article I’ll be showing you all the different ways that you can write queries and it should cover about 90% of the cases that you’ll have when you’re writing your code the other 10% depend on your specific use case you may have to get more complicated but for the most part what I cover in this article should be able to help you so let’s start with the model that I have I’ve already created it.
**Read More : **How to make Chatbot in Python.
Read More : Django Admin Full Customization step by step
let’s just get into this diagram that I made so in here:
Describe each parameter in Django querset
we’re making a simple query for the myModel table so we want to pull out all the information in the database so we have this variable which is gonna hold a return value and we have our myModel models so this is simply the myModel model name so whatever you named your model just make sure you specify that and we’re gonna access the objects attribute once we get that object’s attribute we can simply use the all method and this will return all the information in the database so we’re gonna start with all and then we will go into getting single items filtering that data and go to our command prompt.
Here and we’ll actually start making our queries from here to do this let’s just go ahead and run** Python manage.py shell** and I am in my project file so make sure you’re in there when you start and what this does is it gives us an interactive shell to actually start working with our data so this is a lot like the Python shell but because we did manage.py it allows us to do things a Django way and actually query our database now open up the command prompt and let’s go ahead and start making our first queries.
#django #django model queries #django orm #django queries #django query #model django query #model query #query with django
1595249460
Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub
In this video lesson you will learn:
#docker #docker hub #docker host #docker engine #docker architecture #api
1660510560
Let's look at how to configure a containerized Django app running on an EC2 instance to send logs to Amazon CloudWatch.
Source: https://testdriven.io