You can use Java to write functions in a custom container of Function Compute. This topic describes how to deploy and invoke a Java function. You can also modify
the Spring Boot sample code as needed for custom development.
Procedure
- Run the following command in the specified directory to initialize a project:
s init start-fc-custom-container-http-springboot -d start-cc-http-springboot
Note -d
specifies the name of the folder in which the sample project resides. You can customize
the folder name as required.
- Run the following command to go to the project directory:
cd start-cc-http-springboot
- Optional: Modify the sample code as needed for custom development.
- Modify the s.yaml file.
Change the value of the image
field in the s.yaml file to your image name.
- Run the following command to deploy the project:
s deploy -y
Sample command output:
[2022-02-09 07:04:36] [INFO] [S-CLI] - Start the pre-action
......
helloworld:
region: cn-hangzhou
service:
name: hello-world-service
function:
name: springboot-http-function
runtime: custom-container
handler: not-used
memorySize: 256
timeout: 60
url:
system_url: https://188077086902****.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/hello-world-service/springboot-http-function/
custom_domain:
-
domain: http://springboot-http-function.hello-world-service.188077086902****.cn-hangzhou.fc.devsapp.net
triggers:
-
type: http
name: httpTrigger
Result
After the project is deployed, you can view the temporary domain name that is generated
by Function Compute in the output. The temporary domain name can be used to access
the newly deployed application. For example, run the following command to access the
application:
curl http://springboot-http-function.hello-world-service.188077086902****.cn-hangzhou.fc.devsapp.net
Note You can use the temporary domain name only for demonstration and development purposes.
It is valid for a limited period of time. In a production environment, you must use
a domain name for which an Internet Content Provider (ICP) filing is obtained from
Alibaba Cloud. For more information, see
Configure a custom domain name.