-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from devsapp/add-new
add lindorm and postgresql
- Loading branch information
Showing
19 changed files
with
235 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`案例的初始化、部署整个流程。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cassandra-driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`案例的初始化、部署整个流程。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <your database> | ||
USER: <your user> | ||
PASSWORD: <your password> | ||
# 函数计算FC组件文档参考地址:https://github.com/devsapp/fc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- 新版本支持 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`案例的初始化、部署整个流程。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
psycopg2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`案例的初始化、部署整个流程。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: <your database> | ||
HOST: <your host> | ||
PORT: <your port> | ||
USER: <your user> | ||
PASSWORD: <your password> | ||
# 函数计算FC组件文档参考地址:https://github.com/devsapp/fc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- 新版本支持 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters