Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
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
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
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
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
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
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server 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
Databases
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
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ ModelArts/ Best Practices/ Model Inference/ Enabling an Inference Service to Access the Internet

Enabling an Inference Service to Access the Internet

Updated on 2024-01-09 GMT+08:00

This section describes how to enable an inference service to access the Internet.

Application Scenarios

An inference service accesses the Internet in the following scenarios:

  • After an image is input, the inference service calls OCR on the Internet and then processes data using NLP.
  • The inference service downloads files from the Internet and analyzes the files.
  • The inference service sends back the analysis result to the terminal on the Internet.

Solution Design

Use the algorithm on the instance where the inference service is deployed to access the Internet.

Figure 1 Networking for an inference service to access the Internet

Procedure

  1. Configure the network for the ModelArts resource pool.

    When purchasing a dedicated resource pool, you can select inference services in Job Type. In this case, the selected network must be accessible to the target VPC.
    Figure 2 Purchasing a dedicated resource pool
    Figure 3 Interconnecting the VPC

    Interconnecting a VPC enables the ModelArts resource pool to exchange data with your VPC.

  2. Install and configure a forward proxy for your VPC.

    Before installing a forward proxy, purchase an ECS with the latest Ubuntu image and bind an EIP to the ECS. Then, log in to the ECS, and install and configure a squid forward proxy.

    1. If Docker is not installed, run the following command to install it:
      curl -sSL https://get.daocloud.io/docker | sh
    2. Pull the squid image.
      docker pull ubuntu/squid
    3. Create a host directory and configure whitelist.conf and squid.conf.

      Create a host directory:

      mkdir –p /etc/squid/

      Add the whitelist.conf configuration file. The content is the addresses that can be accessed. For example:

      .apig.cn-east-3.huaweicloudapis.com

      Add the squid.conf configuration file, which includes the following:

      # An ACL named 'whitelist'
      acl whitelist dstdomain '/etc/squid/whitelist.conf'
       
      # Allow whitelisted URLs through
      http_access allow whitelist
       
      # Block the rest
      http_access deny all
       
      # Default port
      http_port 3128

      Set the permissions on the host directory and configuration files:

      chmod 640 -R /etc/squid
    4. Start a squid instance.
      docker run -d --name squid -e TZ=UTC -v /etc/squid:/etc/squid -p 3128:3128 ubuntu/squid:latest
    5. If whitelist.conf or squid.conf is updated, go to the container and update the squid.
      docker exec –it squid bash
      root@{container_id}:/# squid -k reconfigure

  3. Configure the DNS proxy and Internet access URL in the algorithm image.

    1. Set the proxy.

      In the code, specify the private IP address and port of the proxy server, as shown in the following:

      proxies = {
        "http": "http://{proxy_server_private_ip}:3128",
        "https": "http://{proxy_server_private_ip}:3128"
      }

      The following figure shows how to obtain the private IP address of a server.

      Figure 4 Private IP address
    2. Configure the Internet access URL.

      In the inference code, use the service URL to send a service request, for example:

      https://e8a048ce25136addbbac23ce6132a.apig.cn-east-3.huaweicloudapis.com

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback