From 5df66daf720139c2d348c1d5c20eae9bffeb52de Mon Sep 17 00:00:00 2001 From: jbcodeforce Date: Thu, 18 Jan 2024 01:34:56 +0000 Subject: [PATCH] cange to doc and requiremetns --- aws/produceToSQS.py | 7 ++++--- docs/aws/index.md | 6 ++++-- docs/index.md | 5 +++++ requirements.txt | 5 +++++ startPythonDocker.sh | 7 ++----- 5 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 requirements.txt diff --git a/aws/produceToSQS.py b/aws/produceToSQS.py index 18c92b8..8e1b25e 100644 --- a/aws/produceToSQS.py +++ b/aws/produceToSQS.py @@ -1,8 +1,9 @@ -import boto3 +import boto3,os +account_id=os.getenv("AWS_ACCOUNT_ID") sqs = boto3.resource('sqs') -queue = sqs.get_queue_by_name(QueueName='test') +queue = sqs.get_queue_by_name(QueueName='MyQueue',QueueOwnerAWSAccountId=account_id) print("Send a txt messsage") -response = queue.send_message(MessageBody='world') +response = queue.send_message(MessageBody='Hello from client app') print(response.get('MessageId')) print(response.get('MD5OfMessageBody')) \ No newline at end of file diff --git a/docs/aws/index.md b/docs/aws/index.md index 8e449d8..e13661d 100644 --- a/docs/aws/index.md +++ b/docs/aws/index.md @@ -33,9 +33,9 @@ s3 = goto3.service("s3") s3.buckets.all() ``` -### Access DynamoDB +### [Access DynamoDB](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html) -The client have can get the table name using the API client: +The client can get the table name using the API client: ```python import os, boto3 @@ -76,6 +76,8 @@ orderTable.put_item( ``` * Run it once the python virtual env is enabled with `python dynamoClient.py` +* **scan** to run all items from a table. It performs eventually consistent reads +* [**put_item**](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/put_item.html): If an item that has the same primary key as the new item already exists in the specified table, the new item completely replaces the existing item ### [CDK with python](https://jbcodeforce.github.io/aws-studies/coding/cdk/) diff --git a/docs/index.md b/docs/index.md index b3ef452..b1be867 100644 --- a/docs/index.md +++ b/docs/index.md @@ -64,6 +64,11 @@ See [detailed note here](astronomy/README.md) and code is under `astronomy` fold To get some sample code to use AWS SDK [see this folder](https://github.com/jbcodeforce/python-code/blob/master/aws). +## Unit testing + +* [Pytest framework](https://docs.pytest.org/en/7.3.x/#) +* [moto for backend mockup]http://docs.getmoto.org/en/latest/index.html) + ## Some tricks * placing cursor to previous line and enter will copy the line to a new line diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c4ebac3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +mkdocs-material +mkdocs-minify-plugin +#mkdocs-jupyter +#matplotlib +#nbconvert==5.6.1 \ No newline at end of file diff --git a/startPythonDocker.sh b/startPythonDocker.sh index f986606..ee6b1fd 100755 --- a/startPythonDocker.sh +++ b/startPythonDocker.sh @@ -9,9 +9,6 @@ then name=$1 port=$2 fi -if [[ -z "$IPADDR" ]] -then - export IPADDR=$(ifconfig en0 |grep "inet " | awk '{ print $2}') -fi -docker run --rm -e DISPLAY=$IPADDR:0 -v /tmp/.X11-unix:/tmp/.X11-unix --name $name -v $(pwd):/app -it -p $port:$port jbcodeforce/python bash + +docker run --rm -e DISPLAY=host.docker.internal:0 -v /tmp/.X11-unix:/tmp/.X11-unix --name $name -v $(pwd):/app -it -p $port:$port jbcodeforce/python bash