Quickly deploy a Java 11 Event-type OSS trigger function to Alibaba Cloud Function Compute
To use this program, it is recommended that you have the following product permissions/policies prepared:
| Service/Business | Function Compute |
|---|---|
| Permissions/Policies | AliyunFCFullAccess |
To use this project, please prepare the following resources:
| Service/Business | OSS |
|---|---|
| Resource/Create | OSS Bucket |
| Resource/Upload | Upload image file (JPEG, PNG) to OSS Bucket |
| Service/Business | Access control(RAM) |
|---|---|
| Resource/Creat | Ensure AliyunFCDefaultRole exist,The content of this permission can refer tothere |
Deploy by Serverless Devs Cli :
s init oss-trigger-fc-event-java11 -d oss-trigger-fc-event-java11cd oss-trigger-fc-event-java11 && s deploy -yTest the code
s cli fc-event oss and generate OSS Trigger's Sample payload/eventAn example of the generated Event is that the Event is a simulation of a real OSS triggering an incoming Event.
{
"events": [
{
"eventName": "ObjectCreated:PutObject",
"eventSource": "acs:oss",
"eventTime": "2017-04-21T12:46:37.000Z",
"eventVersion": "1.0",
"oss": {
"bucket": {
"arn": "acs:oss:cn-shanghai:123456789:bucketname",
"name": "testbucket",
"ownerIdentity": "123456789",
"virtualBucket": ""
},
"object": {
"deltaSize": 122539,
"eTag": "688A7BF4F233DC9C88A80BF985AB7329",
"key": "image/a.jpg",
"size": 122539
},
"ossSchemaVersion": "1.0",
"ruleId": "9adac8e253828f4f7c0466d941fa3db81161****"
},
"region": "cn-shanghai",
"requestParameters": {
"sourceIPAddress": "140.205.***.***"
},
"responseElements": {
"requestId": "58F9FF2D3DF792092E12044C"
},
"userIdentity": {
"principalId": "123456789"
}
}
]
}
You need to replace the oss resource part in the above example. The regionName, accountId, and bucketName need to be replaced with your own bucket information. Please replace fileName with the image name you uploaded earlier.
"oss": {
"bucket": {
"arn": "acs:oss:${regionName}:${accountId}:${bucketName}",
"name": "${bucketName}",
"ownerIdentity": "${accountId}",
"virtualBucket": ""
},
"object": {
"deltaSize": 122539,
"eTag": "688A7BF4F233DC9C88A80BF985AB7329",
"key": "${fileName}",
"size": 122539
},
}
"region": "${regionName}",
Trigger tests with test samples,run s cli fc invoke --service-name ${serviceNamme} --function-name ${functionName} --event-file event-template/oss-event.json --region ${regionName}
After successful execution, you can query the OSS bucket, and the backup images will be placed in the copy folder.
This application should be only used for learning and reference. You can carry out secondary development and improvement based on this project to realize your own business logic.
If you have feedback about errors or future expectations, you can give and exchange in Serverless Devs repo Issues .If you want to join our discussion group or keep up to date with the latest developments in FC components, you can do so through the following channels:
|
|
|
|
|--- | --- | --- |
| WeChat public account:`serverless` | WeChat Assistant:`xiaojiangwh` | Dingding group:`33947367` |