Ejemplo n.º 1
0
def deploy(settings_module, stage='prod'):
    sys.path.append(os.path.join(os.getcwd(), 'src'))
    settings.load_project_settings(settings_module)

    client = boto3.client('lambda')
    func_name = '{}{}'.format(settings.LAMBDA['Prefix'], to_pascal_case(stage))
    function_arn = 'arn:aws:lambda:{}:{}:function:{}'.format(
        client._client_config.region_name,
        settings.ACCOUNT_ID,
        func_name
    )

    LambdaDeployer(function_arn, stage).deploy('src')
    print 'Lambda deployed'
    api_gateway_url = ApiGatewayDeployer(function_arn, stage).deploy('src')
    if api_gateway_url:
        print 'API Gateway URL: {}'.format(api_gateway_url)
    deployed_names = EventRuleDeployer().deploy()
    if deployed_names:
        print 'Deployed Event Rules:\n\t{}'.format('\n\t'.join(deployed_names))
Ejemplo n.º 2
0
    def handle(self, *options):
        if not options:
            self.show_usage('You must provide a project name')
        project_name = options[0]
        template_dir = os.path.join(noopy.__path__[0], 'project_template')

        os.mkdir(project_name)
        shutil.copytree(os.path.join(template_dir, 'src'), '{}/src'.format(project_name))

        context = dict(
            project_name=project_name,
            lambda_prefix=to_pascal_case(project_name),
        )
        context['account_id'] = raw_input('Input aws account id > ').strip()
        context['role_arn'] = raw_input('Input role arn to be granted to lambda function > ').strip()
        for file_path in glob.glob('{}/*.py'.format(template_dir)):
            with open(file_path, 'r') as f:
                content = f.read()
            filename = os.path.split(file_path)[1]
            with open(os.path.join(project_name, filename), 'w') as f:
                f.write(Template(content).substitute(**context))

        print 'Project "{}" created'.format(project_name)