我正在尝试自动将csv加载到MySQL表中,当它被收到S3存储桶时.
我的策略是S3在收到指定存储桶中的文件时启动一个事件(我们称之为'bucket-file').这是事件被通知给AWS Lambda函数,该函数将下载并处理将每行插入MySql表的文件(让我们称之为'target_table').
我们必须考虑到RDS在VPC中.
存储桶的当前权限配置为:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadForGetBucketObjects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-file/*"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个角色,其中包含以下策略:附加到AWS Lambda函数的AmazonS3FullAccess和AWSLambdaVPCAccessExecutionRole.
lambda代码是:
from __future__ import print_function
import boto3
import logging
import os
import sys
import uuid
import pymysql
import csv
import rds_config
rds_host = rds_config.rds_host
name = rds_config.db_username
password = rds_config.db_password
db_name = rds_config.db_name
logger = logging.getLogger()
logger.setLevel(logging.INFO)
try:
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5)
except Exception as e:
logger.error("ERROR: Unexpected …Run Code Online (Sandbox Code Playgroud) 我们有一个无服务器框架项目,在单一存储库中包含不同的微服务。该项目的结构如下所示:
project-root/
|-services/
|-service1/
|-handler.py
|-serverless.yml
|-service2/
...
|-serviceN/
...
|-bitbucket-pipelines.yml
Run Code Online (Sandbox Code Playgroud)
如您所见,每个服务都有自己的部署文件(serverless.yml)。
我们只想部署在推送/合并中已修改的服务,并且由于我们使用的是 bitbucket-pipelines,所以我们更喜欢使用其功能来实现此目标。
经过一些研究后,我们发现了changesets可以限制目录中已更改文件的步骤的属性。因此,对于每项服务,我们可以在 bitbucket-pipelines.yml 中添加如下内容:
- step:
name: step1
script:
- echo "Deploy service 1"
- ./deploy service1
condition:
changesets:
includePaths:
# only files directly under service1 directory
- "service1/**"
Run Code Online (Sandbox Code Playgroud)
这看起来是一个完美的匹配,但这种方法的问题是我们必须为存储库中的每个服务编写一个步骤,并且如果我们添加更多服务,我们将不得不添加更多步骤,这会影响可维护性和可读性。
有什么方法可以for使用参数化步骤进行循环,其中输入参数是服务名称?
另一方面,我们可以制作一个自定义脚本来处理条件并让部署本身检测更改。即使我们更喜欢 bitbucket-native 方法,我们也愿意接受其他选择;在脚本中执行此操作的最佳方法是什么?
continuous-integration bitbucket continuous-deployment serverless-framework bitbucket-pipelines
我将 Django 和 Neo4j 与 neomodel 一起用作 OGM(用于图形的 ORM)。它运行良好,但在测试方面,Neomodel 不支持关系数据库的常见 Django 行为。我的意思是它不会创建一个在测试开始时创建并在测试结束后销毁的临时 Neo4j 实例。
我一直在做一些研究,我发现了两种可能的解决方案:
第一个是创建一个自定义发现运行器,您可以在其中停止开发数据库,然后从另一条路径启动测试数据库,运行您的测试,最后停止测试实例并再次启动开发实例。这个解决方案是在neo4j数据库的Django测试线程中提出的。以下代码已针对 3.1.1 Neo4j 版本进行了调整:
from time import sleep
from subprocess import call
from django.test.runner import DiscoverRunner
from py2neo import authenticate
class DiscoverRunner(DiscoverRunner):
def setup_databases(self, *args, **kwargs):
# Stop your development instance
call("sudo neo4j stop", shell=True)
# Sleep to ensure the service has completely stopped
sleep(1)
# Start your test instance (see section below for more details)
success = call("neo4j_test/neo4j-community-3.1.1/bin/neo4j"
" start", shell=True)
# …Run Code Online (Sandbox Code Playgroud)We want to build an ECS cluster with the following characteristics:
amazon-s3 ×2
python ×2
amazon-ecs ×1
aws-lambda ×1
bitbucket ×1
django ×1
mysql ×1
neo4j ×1
terraform ×1
testing ×1