All Products
Search
Document Center

Serverless App Engine:Configure OSS storage

Last Updated:Sep 03, 2024

Object Storage Service (OSS) provides the console and easy-to-use tools to allow you to manage buckets in a visualized manner. You can persistently store instance data and distribute data across instances to reduce costs. OSS is suitable for scenarios in which you need to perform more read operations than write operations, such as mounting configuration files or frontend static files.

Prerequisites

Procedure

Configure OSS storage when you create an application

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click Create Application.

  3. In the Basic Information step, configure the parameters and click Next: Application Deployment Configurations.

  4. In the Deployment Configurations step, configure the Technology Stack Programming Language and Application Deployment Method parameters and the corresponding settings.

  5. In the Persistent Storage section, click the OSS tab and configure the parameters.

    1. Configure the AccessKey ID and AccessKey Secret parameters.

      We recommend that you follow the best practices of Alibaba Cloud and use the AccessKey pair of a RAM user to call OSS API operations. You must make sure that the RAM user is granted the least permissions to access OSS resources. The following sample code shows the read-only permissions that you can grant to a RAM user on the oss-test/ directory of the test-sae bucket:

      {
          "Statement": [
              {
                  "Action": "oss:GetBucket",
                  "Effect": "Allow",
                  "Resource": "acs:oss:*:*:test-sae"
              },
              {
                  "Action": "oss:GetObject",
                  "Effect": "Allow",
                  "Resource": "acs:oss:*:*:/"
              }
          ],
          "Version": "1"
      }
    2. Click Add and configure the parameters. The following table describes the parameters.

      Parameter

      Description

      Example

      Bucket

      The existing OSS bucket.

      bucketname

      Mount Directory

      The existing OSS directory or OSS object. If the specified directory or object is invalid, an exception occurs.

      Example:

      • /

        Note

        / indicates the root directory to which the bucket is mounted.

      • tmp/oss-test/

      • tmp/oss-demo.log

      Container Path

      The container path of SAE. The directory that you specify overwrites the original value. If the directory that you specify does not exist, SAE automatically creates a directory.

      /home/admin/app/php/

      Permission

      The permissions of the application to access OSS resources that are mounted to the Mount Directory through Container Path. Valid values:

      • Read-Only

      • Read-Write

      Read-Only

  6. Click Next: Confirm Specifications.

  7. In the Specification Confirmation step, view the details of the application and the fee for the selected specifications. Then, click Confirm.

    The Creation Completed step appears. You can click Application Details to go to the Basic Information page of the application.

Configure OSS storage when you deploy an application

Warning

After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.

The procedure that can be performed to update an application varies based on the number of instances in the application. This section provides an example on how to configure the required features for an application in which the number of instances is greater than or equal to 1. For information about how to update an application in which the number of instances is 0, see Update an application.

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Applications. In the top navigation bar, select a region. Then, click the name of an application.

  3. In the upper-right corner of the Basic Information page, click Deploy Application.

  4. In the Persistent Storage section, click the OSS tab and configure the parameters.

    1. Configure the AccessKey ID and AccessKey Secret parameters.

      We recommend that you follow the best practices of Alibaba Cloud and use the AccessKey pair of a RAM user to call OSS API operations. You must make sure that the RAM user is granted the least permissions to access OSS resources. The following sample code shows the read-only permissions that you can grant to a RAM user on the oss-test/ directory of the test-sae bucket:

      {
          "Statement": [
              {
                  "Action": "oss:GetBucket",
                  "Effect": "Allow",
                  "Resource": "acs:oss:*:*:test-sae"
              },
              {
                  "Action": "oss:GetObject",
                  "Effect": "Allow",
                  "Resource": "acs:oss:*:*:/"
              }
          ],
          "Version": "1"
      }
    2. Click Add and configure the parameters. The following table describes the parameters.

      Parameter

      Description

      Example

      Bucket

      The existing OSS bucket.

      bucketname

      Mount Directory

      The existing OSS directory or OSS object. If the specified directory or object is invalid, an exception occurs.

      Example:

      • /

        Note

        / indicates the root directory to which the bucket is mounted.

      • tmp/oss-test/

      • tmp/oss-demo.log

      Container Path

      The container path of SAE. The directory that you specify overwrites the original value. If the directory that you specify does not exist, SAE automatically creates a directory.

      /home/admin/app/php/

      Permission

      The permissions of the application to access OSS resources that are mounted to the Mount Directory through Container Path. Valid values:

      • Read-Only

      • Read-Write

      Read-Only

  5. After you configure the settings, click Confirm.

Unmount the OSS bucket

Warning

After you redeploy an application, the application is restarted. To prevent unpredictable errors such as business interruptions, we recommend that you deploy applications during off-peak hours.

If you no longer use OSS storage after you mount an OSS bucket, you can unmount the OSS bucket. After you unmount an OSS bucket in the SAE console, the data that is stored in the OSS bucket is retained. For more information, see Configure OSS storage when you deploy an application. Follow Step 4 to find the OSS storage configuration that you want to unmount and click the oss-mount-delete-icon icon in the Actions column.

Verify the mount result

Use one of the following methods to check whether the OSS bucket is mounted based on your business requirements:

  • Verify the mount result based on change records.

    If no exception occurs on the instances that are generated after you configure OSS storage during application creation or deployment, the OSS bucket is mounted.

    sae挂载nas成功

  • Verify the mount result based on containers.

    Run the following command in the webshell of an instance to check whether the mount information of the OSS bucket exists in the application:

    cat /proc/mounts | grep ossfs

    If the following output is returned, the OSS bucket is mounted.oss_success

  • Verify the mount result based on your business.

    Run commands in the path on which the OSS bucket is mounted in a webshell. If the operation records can be found in the OSS console, the OSS bucket is mounted.

FAQ

Can I use OSS to store logs?

We recommend that you do not use OSS as a log persistence tool. OSS is suitable for scenarios that require mass data processing, such as image, audio, and video files. OSS is also suitable for scenarios in which static and dynamic resources on web pages and mobile applications are separated.

We recommend that you use Simple Log Service in log scenarios to ensure log data persistence. For more information, see Configure log collection to Simple Log Service.