Deploy a flexible and highly available image processing service within 10 minutes

简介: Alibaba Cloud Function Compute is an event-driven and fully-managed compute service. With Function Compute, you can quickly build any type of applicat.

Prefaces

Alibaba Cloud Function Compute is an event-driven and fully-managed compute service. With Function Compute, you can quickly build any type of applications or services without considering management or O&M. You can complete a set of backend services for processing multimedia data even in several days. In this tutorial,we will deploy a flexible and highly avaliable image processing service in 10 minutes with FC.

Image processing service example

Take the classic lena in image processing for example:
image

The entry of image processing example:

Effect Picture:

image

image

Function Entry

We use python runtime to complete this tutorial. Let's look at a few concepts before we get started.

common handlers

def my_handler(event, context):
    return 'hello world'
  • Function name

The function name must match the “handler” field provided when a function is created. For example, if handler is specified as main.my_handler, Function Compute obtains the my_handler function defined in main.py.

  • Parameter event

The event parameter is defined when you call a function. In Python 2.7, this parameter is of str type. In Python 3, it is of bytes type. The parameter is an input parameter.

  • Parameter context

The context parameter contains information generated when the function is executed, for example, the request ID and temporary AccessKey credentials. You can use the generated information when coding. This parameter is of the FCContext type.

  • Return value

The return value of a function can be returned to the users as the result of invoke function. It can be any type. Function Compute can return it as str for simple type; and it can be returned as JSON str for complex type.

Handlers with an HTTP trigger

HELLO_WORLD = b"Hello world!\n"
def handler(environ, start_response):
    context = environ['fc.context']
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return [HELLO_WORLD]
  • environ : This parameter represents a Python dictionary that stores all client-related information. For more information, see Parameter environ,Two user-defined keys, fc.context and fc.request_uri, are added to Function Compute.

    • fc.context : functions as the context parameter of common handlers.
    • fc.request_uri : indicates the URL of the request. This parameter is a string.

Note: The HTTP_Variables field of environ contains the request header. For example, if the request header is 'x-Custom-key':'value', the environ parameter will be environ['HTTP_X_CUSTOM_KEY'] ='value'. According to WSGI, the key in the request header is processed as follows: key = "HTTP_" + k.upper().replace("-","_").

  • start_response: The start_response callable is provided in runtime environments of Function Compute. It has two required positional parameters and one optional parameter. For more information, see the-start-response-callable. In the following example, the three parameters are named status, response_headers, and exc_info. You can use other names as needed.

More details can be found at python handler

Specific steps

Assuming that all the operations are finished in Shenzhen(China south 1) region, all the relevant resources can be download in the attachment.

There are two types of deployment:

  1. Use fun tools for automatic deployment
  2. Use fc console for visual deployment

Preparations

  • Preparing pictures to the specified oss bucket

For example, build a bucket named xiamen-ws in Shenzhen(China south 1) region, where store the four pictures(you can casually name the bucket)

image

Use the fun tool for automatic deployment

Fun is a development tool for serverless applications. It can help you to efficiently arrange cloud resources such as Function Compute, API Gateway, Log Service and so on. You can use it to develop,build and deploy FC by describing relative resources in a template.yml file. The most basic serverless application can have only one function.

Take this case as example, the yaml file can be defined as follows:

ROSTemplateFormatVersion: '2015-09-01'
Transform: 'Aliyun::Serverless-2018-04-03'
Resources:
  image-demo-pro:
    Type: 'Aliyun::Serverless::Log'
    Properties:
      Description: 'image process log pro'
    fc-log:
      Type: 'Aliyun::Serverless::Log::Logstore'
      Properties:
        TTL: 362
        ShardCount: 1 
  
  image-service:
    Type: 'Aliyun::Serverless::Service'
    Properties:
      Description: 'image process demo'
      Policies:
        - AliyunOSSFullAccess
      LogConfig:
        Project: 'image-demo-pro'
        Logstore: 'fc-log'
    image-proc:
      Type: 'Aliyun::Serverless::Function'
      Properties:
        Handler: main.handler
        CodeUri: './'
        Description: 'image-process http function'
        Runtime: python2.7
        Timeout: 60
        MemorySize: 512
      Events:
        http-trigger:
          Type: HTTP
          Properties:
            AuthType: ANONYMOUS
            Methods: ['GET', 'POST', 'PUT']

Using the yaml file defined above, you can do the following:

  1. Create log resources: logproject:image-demo-pro, logstore:fc-log
  2. Create service: image-service and function: image-proc, configurating function with a trigger named http-trigger.
  3. Configurate service role and logconfig, role permission is AliyunOSSFullAccess and the authority of function execution log store into fc-log.

Specific deployment operation

  • Install nodejs (version>8)
  • Install fun
  npm install git://github.com/aliyun/fun.git --save -g
  • Modify the name of logproject and the related configuration in template.yml. After fun deploy has been executed successfully, you may see the following resources being crested, screenshot:

image
image

FC Console setup

Create service/function, and configurate http trigger

  • Create a new service, configurate service with the role of oss permission

image

image

  • Create function, and configurate Http trigger

image

image

image

image

Summary

Function compute has advantages as follows:

  • No infrastructure - No need to purchase and manage server
  • Focus on Business - Focusing on the development of business logic can greatly improve development efficiency
  • Traceable - Provide log query, performance monitoring, alarm and other functions to quickly troubleshoot.
  • Stable and Reliable - Stable , Highly availability, millisecond-level elastic scaling to cope up with peak demand pressure.
  • Flexible Pricing - Pay-as-you-go, You only pay for the time your code runs. Function Compute is suitable for high traffic-fluctuation scenarios

The official website of Function Compute

相关实践学习
【玩转ComfyUI】基于函数计算一键部署AI生图平台ComfyUI
本次实验将带大家通过使用阿里云产品函数计算FC,快速使用ComfyUI实现更高质量的图像生成。
从 0 入门函数计算
在函数计算的架构中,开发者只需要编写业务代码,并监控业务运行情况就可以了。这将开发者从繁重的运维工作中解放出来,将精力投入到更有意义的开发任务上。
目录
相关文章
|
6月前
|
SQL 数据可视化 开发者
Dataphin功能Tips系列(90)告别“查无数据”,行级权限自助申请功能上线
Dataphin推出行级权限可视化提示与自助申请功能,帮助分析师快速识别“无数据”原因(如被自动过滤),并一键提交权限申请。审批通过后即可查询全量数据,大幅降低沟通成本,提升分析效率。
265 8
|
25天前
|
数据采集 人工智能 自然语言处理
从工具到“硅基员工”:2026年中国企业级AI Agent竞争版图全解析
2026年,中国AI Agent迈入规模化落地“验收期”:企业不再比参数,而考察能否对接ERP、处理非结构化数据、对业务结果负责。瓴羊AgentOne以“Data+AI+FDE”三角能力,打造懂数据、可执行、能迭代的“硅基员工”,推动AI从对话工具升级为业务责任人。
|
3月前
|
人工智能 缓存 开发框架
阿里云Qwen3.7-Max限时优惠:5折起,输入6元/每百万tokens,输出18元/每百万tokens
Qwen3.7-Max是通义千问面向智能体时代的旗舰大模型,在编程能力(Code Arena全球第二)、智能体执行、长程推理及多语言理解等维度均达行业顶尖水平,支持1M token超长上下文、35小时长周期自主执行及1158次工具调用,已在蔚来汽车工程中验证AI代码生成占比超70%。当前限时5折,输入6元/百万tokens、输出18元/百万tokens,全模型通用节省计划低至4.5折,新用户还可享100万免费tokens(90天有效)。无论开发者探索AI编程,还是企业构建智能体系统,Qwen3.7-Max都是当下高性价比的全能之选。
|
3月前
|
缓存 弹性计算 运维
运维不再需要“老师傅”——OS 运维 Skills 发布,欢迎体验
让任何运维 Agent 具备资深内核专家的诊断能力。
|
4月前
|
人工智能 运维 Serverless
作为一名独立开发者,我为什么放弃了本地 GPU,转向 Serverless 部署 AI 模型?
本文以真实经历切入,剖析本地部署AI模型的四大痛点(环境配置难、噪音电费高、利用率低、弹性差),揭示独立开发者面临的硬件、运维与成本三重困境。重点推介Serverless GPU方案——按调用付费、极致弹性、一键部署预置AI模板(如Flux、GPT-Sovits),大幅降低MVP验证门槛。理性指出其适用边界,倡导“调用能力”替代“拥有显卡”的新范式。(239字)
|
4月前
|
人工智能 自然语言处理 运维
2026年企业AI客服系统盘点,智能客服系统建设费用与降本增效实施策略
本文解析AI客服建设费用分层逻辑,详解瓴羊Quick Service针对小微、中型、大型企业的差异化定价(年费1万至200万元+),并提供智能路由、知识库自学习、人机协同等全链路降本增效策略,助力企业实现可量化、可落地的智能客服升级。(239字)
|
3月前
|
API 定位技术 开发工具
金融行业的IP风控反欺诈服务怎么选?3个合规指标+离线库方案
本文剖析金融IP风控三大合规痛点:数据不出境、业务零中断、决策全审计,提出私有化部署、高可用架构、全量审计三大选型指标,并详解离线库落地实践,助力金融机构构建真正合规、可靠、可溯的反欺诈体系。(239字)
|
5月前
|
人工智能 自然语言处理 数据挖掘
大模型应用:因果推理赋能大模型:从关联分析到因果决策的升级路径.80
本文探讨大模型与因果推理的深度融合:大模型擅长发现相关性但易产生幻觉,而因果推理能识别真实因果、支持干预与反事实分析。通过因果图、do-演算、SCM等工具,二者互补升级——大模型提升因果建模能力,因果推理增强大模型的可解释性、鲁棒性与决策力,推动AI从“知其然”迈向“知其所以然”。
597 2
|
6月前
|
存储 JSON 安全
接口安全:签名、加密、防重放架构方案
本文详解接口安全三大核心防线:签名(防篡改/伪造)、加密(防窃听/泄露)、防重放(防复用攻击)。厘清三者边界与协同逻辑,提供生产级规范、主流算法选型及完整Java代码实现,助开发者构建真正安全的全链路接口防护体系。
1009 2

热门文章

最新文章