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

Package

Updated on 2023-11-22 GMT+08:00

Packaging CLI Command

Using the Serverless CLI tool, you can package your project without deploying it to Huawei Cloud. This is best used with CI/CD workflows to ensure consistent deployable artifacts.

Running the following command will build and save all of the deployment artifacts in the .serverless directory of the service:
serverless package

Packaging Configuration

If you want to have more control over function artifacts and package methods.

You can use the patterns configuration.

  • Patterns

    Patterns allow you to define globs that will be excluded/included from the resulting artifact. If you want to exclude files, you can use a global pattern prefixed with !, such as !exclude-me/**. Serverless Framework will run the global patterns so that you can always re-include previously excluded files and directories.

    Examples

    Exclude all node_modules but then re-include a specific module (node-fetch in this case) using exclude
    package:
      patterns:
        - '!node_modules/**'
        - 'node_modules/node-fetch/**'
    Exclude all files but handler.js
    package:
      patterns:
        - '!src/**'
        - src/function/handler.js
    NOTE:
    If you want to exclude directories, use the correct global syntax. The following is an example:
    package:
      patterns:
        - '!tmp/**'
        - '!.git/**'
  • Artifact

    For complete control over the packaging process, you can specify your own artifact ZIP file.

    Serverless will not zip your service if this is configured and therefore patterns will be ignored. Either you use artifact or patterns.

    The artifact option is especially useful if your development environment allows you to generate a deployable artifact like Maven does for Java.

    Example
    service: my-service
    package:
      patterns:
        - '!tmp/**'
        - '!.git/**'
        - some-file
      artifact: path/to/my-artifact.zip
  • Package functions separately

    If you want even more control over your functions for deployment, you can configure them to be packaged separately. This allows for more control to optimize your deployment. To enable individual packaging, set individually to true in the packaging settings of the service or the function.

    Then for every function you can use the same patterns or artifact configuration options. The patterns options will be merged with the service options to create a patterns configuration for each function during packaging.
    service: my-service
    package:
      individually: true
      patterns:
        - '!excluded-by-default.json'
    functions:
      hello:
        handler: handler.hello
        package:
          # We're including this file so it will be in the final package of this function only
          patterns:
            - excluded-by-default.json
      world:
        handler: handler.hello
        package:
          patterns:
            - '!some-file.js'
    You can also select which functions to be packaged separately, and have the rest use the service package by setting the individually to true.
    service: my-service
    functions:
      hello:
        handler: handler.hello
      world:
        handler: handler.hello
        package:
          individually: true
  • Development Dependencies

    Serverless will auto-detect and exclude development dependencies based on the runtime your service is using to ensure that only the production relevant packages and modules are included in your ZIP file. This drastically reduces the overall size of the deployment package which will be uploaded to the cloud provider.

    You can opt out of automatic exclusion of development dependency by setting the excludeDevDependencies to false:
    package:
      excludeDevDependencies: false

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