diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 31cdc3d..b504779 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -60,4 +60,24 @@ jobs: wget https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py ls python hub-publish.py + cd .. + + - name: fc-postgresql-python + env: + publish_token: ${{ secrets.alibaba_registry_publish_token }} + run: | + cd postgresql + wget https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py + ls + python hub-publish.py + cd .. + + - name: fc-lindorm-python + env: + publish_token: ${{ secrets.alibaba_registry_publish_token }} + run: | + cd lindorm + wget https://serverless-registry.oss-cn-hangzhou.aliyuncs.com/publish-file/python3/hub-publish.py + ls + python hub-publish.py cd .. \ No newline at end of file diff --git a/lindorm/publish.yaml b/lindorm/publish.yaml new file mode 100644 index 0000000..f6cd351 --- /dev/null +++ b/lindorm/publish.yaml @@ -0,0 +1,20 @@ +Type: Application +Name: start-fc-lindorm-python +Version: 0.0.3 +Provider: + - 阿里云 +Description: 快速部署一个 Python 访问 lindorm 的函数到阿里云函数计算。 +HomePage: https://github.com/devsapp/start-fc-db-python +Tags: + - 函数计算 + - 你好世界 + - 新手入门 +Category: 新手入门 +Service: + 函数计算: + Authorities: + - 创建函数 + - 删除函数 + - 创建服务 + - 删除服务 + Runtime: Python \ No newline at end of file diff --git a/lindorm/readme.md b/lindorm/readme.md new file mode 100644 index 0000000..e5fae66 --- /dev/null +++ b/lindorm/readme.md @@ -0,0 +1,12 @@ +# 阿里云函数计算 Python 访问 Lindorm 云数据库 + +只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库 + +- 初始化项目:`s init start-fc-lindorm-python -d start-fc-lindorm-python` +- 进入项目:`cd start-fc-lindorm-python` +- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的 +- 构建项目:`s build --use-docker` +- 部署项目:`s deploy` +- 触发项目:`s invoke` + +即可实现`Python 访问 Lindorm`案例的初始化、部署整个流程。 diff --git a/lindorm/src/code/index.py b/lindorm/src/code/index.py new file mode 100644 index 0000000..469193a --- /dev/null +++ b/lindorm/src/code/index.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +import logging +import os +from cassandra.cluster import Cluster +from cassandra.auth import PlainTextAuthProvider + +logger = logging.getLogger() + + +def handler(event, context): + logger.info("start to test Lindorm ") + addr_str = os.environ['DATABASE_ADDR'] + cluster = Cluster( + # 配置连接地址。 + contact_points=addr_str.split(","), + # 配置用户名和密码。 + auth_provider=PlainTextAuthProvider(os.environ['USER'], os.environ['PASSWORD'])) + session = cluster.connect() + session.execute( + "CREATE KEYSPACE IF NOT EXISTS testKeyspace WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};") + session.execute( + "CREATE TABLE IF NOT EXISTS testKeyspace.testTable (id int PRIMARY KEY, name text,age int,address text);") + session.execute( + "INSERT INTO testKeyspace.testTable (id, name, age, address) VALUES ( 1, 'testname', 11, 'hangzhou');") + rows = session.execute("SELECT * FROM testKeyspace.testTable ;") + for row in rows: + logger.info("# row: {}".format(row)) + + session.shutdown() + cluster.shutdown() diff --git a/lindorm/src/code/requirements.txt b/lindorm/src/code/requirements.txt new file mode 100644 index 0000000..a94062d --- /dev/null +++ b/lindorm/src/code/requirements.txt @@ -0,0 +1 @@ +cassandra-driver \ No newline at end of file diff --git a/lindorm/src/readme.md b/lindorm/src/readme.md new file mode 100644 index 0000000..e5fae66 --- /dev/null +++ b/lindorm/src/readme.md @@ -0,0 +1,12 @@ +# 阿里云函数计算 Python 访问 Lindorm 云数据库 + +只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库 + +- 初始化项目:`s init start-fc-lindorm-python -d start-fc-lindorm-python` +- 进入项目:`cd start-fc-lindorm-python` +- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的 +- 构建项目:`s build --use-docker` +- 部署项目:`s deploy` +- 触发项目:`s invoke` + +即可实现`Python 访问 Lindorm`案例的初始化、部署整个流程。 diff --git a/lindorm/src/s.yaml b/lindorm/src/s.yaml new file mode 100644 index 0000000..4d86c34 --- /dev/null +++ b/lindorm/src/s.yaml @@ -0,0 +1,26 @@ +edition: 1.0.0 # 命令行YAML规范版本,遵循语义化版本(Semantic Versioning)规范 +name: fcDeployApp # 项目名称 +access: "{{ access }}" # 秘钥别名 + +services: + fc-db-lindorm-python: # 服务名称 + component: devsapp/fc # 组件名称 + props: # 组件的属性值 + region: cn-hangzhou + service: + name: fc-db-demo + description: 'demo for fc visit db' + internetAccess: true + function: + name: lindorm + description: visit lindorm + runtime: python3 + codeUri: ./code + handler: index.handler + memorySize: 256 + timeout: 30 + environmentVariables: + DATABASE_ADDR: + USER: + PASSWORD: +# 函数计算FC组件文档参考地址:https://github.com/devsapp/fc \ No newline at end of file diff --git a/lindorm/version.md b/lindorm/version.md new file mode 100644 index 0000000..b51e0aa --- /dev/null +++ b/lindorm/version.md @@ -0,0 +1 @@ +- 新版本支持 \ No newline at end of file diff --git a/mongodb/publish.yaml b/mongodb/publish.yaml index e9108b7..a9b8567 100644 --- a/mongodb/publish.yaml +++ b/mongodb/publish.yaml @@ -1,6 +1,6 @@ Type: Application Name: start-fc-mongodb-python -Version: 0.0.2 +Version: 0.0.3 Provider: - 阿里云 Description: 快速部署一个 Python 访问 mongodb 的函数到阿里云函数计算。 diff --git a/mysql/publish.yaml b/mysql/publish.yaml index dbe7028..5f10e23 100644 --- a/mysql/publish.yaml +++ b/mysql/publish.yaml @@ -1,6 +1,6 @@ Type: Application Name: start-fc-mysql-python -Version: 0.0.2 +Version: 0.0.3 Provider: - 阿里云 Description: 快速部署一个 Python 访问 mysql 的函数到阿里云函数计算。 diff --git a/postgresql/publish.yaml b/postgresql/publish.yaml new file mode 100644 index 0000000..6a3309d --- /dev/null +++ b/postgresql/publish.yaml @@ -0,0 +1,20 @@ +Type: Application +Name: start-fc-postgresql-python +Version: 0.0.3 +Provider: + - 阿里云 +Description: 快速部署一个 Python 访问 postgresql 的函数到阿里云函数计算。 +HomePage: https://github.com/devsapp/start-fc-db-python +Tags: + - 函数计算 + - 你好世界 + - 新手入门 +Category: 新手入门 +Service: + 函数计算: + Authorities: + - 创建函数 + - 删除函数 + - 创建服务 + - 删除服务 + Runtime: Python \ No newline at end of file diff --git a/postgresql/readme.md b/postgresql/readme.md new file mode 100644 index 0000000..1a555d7 --- /dev/null +++ b/postgresql/readme.md @@ -0,0 +1,12 @@ +# 阿里云函数计算 Python 访问 postgresql 数据库 + +只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库 + +- 初始化项目:`s init start-fc-postgresql-python -d start-fc-postgresql-python` +- 进入项目:`cd start-fc-postgresql-python` +- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的 +- 构建项目:`s build --use-docker` +- 部署项目:`s deploy` +- 触发项目:`s invoke` + +即可实现`Python 访问 postgresql`案例的初始化、部署整个流程。 diff --git a/postgresql/src/code/index.py b/postgresql/src/code/index.py new file mode 100644 index 0000000..fa4a775 --- /dev/null +++ b/postgresql/src/code/index.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +import logging +import psycopg2 +import os +import sys +logger = logging.getLogger() + + +def getConnection(): + try: + conn = psycopg2.connect( + database=os.environ['DATABASE'], + user=os.environ['USER'], + password=os.environ['PASSWORD'], + host=os.environ['HOST'], + port=os.environ['PORT'], + ) + return conn + except Exception as e: + logger.error(e) + logger.error( + "ERROR: Unexpected error: Could not connect to PostgreSQL instance.") + raise Exception(str(e)) + + +def handler(event, context): + conn = getConnection() + try: + cur = conn.cursor() + cur.execute("INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) \ + VALUES (1, 'Paul', 32, 'California', 20000.00 )") + conn.commit() + return 'successfully' + finally: + conn.close() diff --git a/postgresql/src/code/requirements.txt b/postgresql/src/code/requirements.txt new file mode 100644 index 0000000..ddb37e1 --- /dev/null +++ b/postgresql/src/code/requirements.txt @@ -0,0 +1 @@ +psycopg2 \ No newline at end of file diff --git a/postgresql/src/readme.md b/postgresql/src/readme.md new file mode 100644 index 0000000..1a555d7 --- /dev/null +++ b/postgresql/src/readme.md @@ -0,0 +1,12 @@ +# 阿里云函数计算 Python 访问 postgresql 数据库 + +只需几步就可以快速在阿里云函数计算服务上体验 Python 访问 redis 数据库 + +- 初始化项目:`s init start-fc-postgresql-python -d start-fc-postgresql-python` +- 进入项目:`cd start-fc-postgresql-python` +- 将 s.yaml 中的环境变量修改成您自己的值, 并将数据库操作代码改成您需要的 +- 构建项目:`s build --use-docker` +- 部署项目:`s deploy` +- 触发项目:`s invoke` + +即可实现`Python 访问 postgresql`案例的初始化、部署整个流程。 diff --git a/postgresql/src/s.yaml b/postgresql/src/s.yaml new file mode 100644 index 0000000..25b649c --- /dev/null +++ b/postgresql/src/s.yaml @@ -0,0 +1,28 @@ +edition: 1.0.0 # 命令行YAML规范版本,遵循语义化版本(Semantic Versioning)规范 +name: fcDeployApp # 项目名称 +access: "{{ access }}" # 秘钥别名 + +services: + fc-db-postgresql-python: # 服务名称 + component: devsapp/fc # 组件名称 + props: # 组件的属性值 + region: cn-hangzhou + service: + name: fc-db-demo + description: 'demo for fc visit db' + internetAccess: true + function: + name: postgresql + description: visit postgresql + runtime: python3 + codeUri: ./code + handler: index.handler + memorySize: 256 + timeout: 30 + environmentVariables: + DATABASE: + HOST: + PORT: + USER: + PASSWORD: +# 函数计算FC组件文档参考地址:https://github.com/devsapp/fc \ No newline at end of file diff --git a/postgresql/version.md b/postgresql/version.md new file mode 100644 index 0000000..b51e0aa --- /dev/null +++ b/postgresql/version.md @@ -0,0 +1 @@ +- 新版本支持 \ No newline at end of file diff --git a/redis/publish.yaml b/redis/publish.yaml index 421b986..f77231f 100644 --- a/redis/publish.yaml +++ b/redis/publish.yaml @@ -1,6 +1,6 @@ Type: Application Name: start-fc-redis-python -Version: 0.0.2 +Version: 0.0.3 Provider: - 阿里云 Description: 快速部署一个 Python 访问 redis 的函数到阿里云函数计算。 diff --git a/sql_server/publish.yaml b/sql_server/publish.yaml index b408470..940ab53 100644 --- a/sql_server/publish.yaml +++ b/sql_server/publish.yaml @@ -1,6 +1,6 @@ Type: Application Name: start-fc-sql-server-python -Version: 0.0.2 +Version: 0.0.3 Provider: - 阿里云 Description: 快速部署一个 Python 访问 sql-server 的函数到阿里云函数计算。