Este conteúdo foi traduzido por máquina para sua conveniência e a Huawei Cloud não pode garantir que o conteúdo foi traduzido com precisão. Para exibir o conteúdo original, use o link no canto superior direito para mudar para a página em inglês.
Computação
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Redes
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Gerenciamento e governança
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
Cloud Operations Center
Resource Governance Center
Migração
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Análises
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
IoT
IoT Device Access
Outros
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Segurança e conformidade
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Serviços de mídia
Media Processing Center
Video On Demand
Live
SparkRTC
Armazenamento
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Cloud Server Backup Service
Storage Disaster Recovery Service
Scalable File Service
Volume Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Bancos de dados
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Aplicações de negócios
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Data Lake Factory
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Distribuição de conteúdo e computação de borda
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Soluções
SAP Cloud
High Performance Computing
Serviços para desenvolvedore
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
Cloud Application Engine
MacroVerse aPaaS
KooPhone
KooDrive
Central de ajuda/ FunctionGraph/ Referência de API/ Exemplos/ Exemplo 3: Criação de uma função por carregamento de código em um bucket do OBS

Exemplo 3: Criação de uma função por carregamento de código em um bucket do OBS

Atualizado em 2022-11-08 GMT+08:00

Cenário

Este exemplo orienta você pelo procedimento para fazer upload de código local em um bucket dõ Object Storage Service (OBS) e criar uma função do Python 2.7 usando o URL do link do bucket do OBS.

Para obter detalhes sobre como chamar as API, consulte Chamada das API.

Pré-requisitos

Um bucket do OBS foi criado.

Procedimento geral

Depois de escrever o código da função no ambiente local, carregue o arquivo de código em um bucket de OBS e use o URL do link do bucket do OBS para criar uma função. O procedimento é o seguinte:

  1. Escreva código em seu ambiente local para criar um projeto de função.
  2. Compacte o arquivo de código em um pacote ZIP, carregue o pacote no bucket do OBS e registre o URL do link desse bucket.
  3. Chame a API em Criação de uma função para criar uma função usando o URL do link do bucket do OBS.

Passo 1: Criar um projeto de função

  1. Escreva código para imprimir texto helloworld.

    Abra um editor de texto, compile uma função HelloWorld e salve o arquivo de código como helloworld.py. O código é o seguinte:

    def printhello(): 
        print 'Hello world!' 
  2. Defina uma função FunctionGraph.

    Abra um editor de texto, defina uma função e salve o arquivo de função como index.py no mesmo diretório do arquivo helloworld.py. O código da função é o seguinte:

    import json 
    import helloworld 
     
    def handler (event, context): 
        output =json.dumps(event) 
        helloworld.printhello() 
        return output

Passo 2: Carregue o projeto em um bucket do OBS

  1. No projeto de função, selecione os arquivos helloworld.py e index.py e compacte-os em fss_examples_python2.7.zip.
  2. Faça upload do pacote fss_examples_python2.7.zip para o bucket do OBS e registre o URL do link do bucket do OBS.

Passo 3: Chame a API de criação de função para criar uma função usando o URL do link do bucket do OBS

URI: POST /v2/{project_id}/fgs/functions

Para obter detalhes, consulte Criação de uma função.

  • Exemplo de solicitação
    POST  https://{Endpoint}/v2/{project_id}/fgs/functions
    {
     "code_type": "obs",
     "code_url": "https://test.obs.xxx.xxx.com/fss_examples_python2.7.zip",
     "func_name": "create_function_from_obs",
     "handler": "index.handler",
     "memory_size": 256,
     "package": "default",
     "runtime": "Python2.7",
     "timeout": 30
    }

    code_url indica o URL do link do bucket do OBS registrado em 2.

  • Exemplo de resposta
    {
     "func_urn": "urn:fss:{project_name}:{project_id}:function:default:create_function_from_obs:latest",
     "func_name": "create_function_from_obs",
     "domain_id": "0503xxxa960",
     "namespace": "{project_id}",
     "project_name": "xxx",
     "package": "default",
     "runtime": "Python2.7",
     "timeout": 30,
     "handler": "index.handler",
     "memory_size": 256,
     "cpu": 400,
     "code_type": "obs",
     "code_url": "https://test.obs.xxx.xxx.com/fss_examples_python2.7.zip",
     "code_filename": "fss_examples_python2.7.zip",
     "code_size": 436,
     "digest": "3af770ada27514564b1a20d964cba4b35f432fa40f9fc4f4f7c1f0d2f42eac6cb4db1358c195235966b05f66b4664e7bf31c3f384a9066b3d1fcc3e96b4c3f65",
     "version": "latest",
     "image_name": "latest-200619100734@gjf4p",
     "last_modified": "2020-06-19T10:07:34+08:00",
     "strategy_config": {
      "concurrency": -1
     },
     "StrategyConfig": {},
     "enterprise_project_id": "0"
    }

Usamos cookies para aprimorar nosso site e sua experiência. Ao continuar a navegar em nosso site, você aceita nossa política de cookies. Saiba mais

Feedback

Feedback

Feedback

0/500

Conteúdo selecionado

Envie o conteúdo selecionado com o feedback