From 2bb9d28704d75f4101d5e75923a76aba541c97f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=BE=E5=93=92?= Date: Fri, 26 Mar 2021 16:58:27 +0800 Subject: [PATCH 1/2] add single AccessKey and AccessKeySecret support --- .../EdasContextAutoConfiguration.java | 25 ++- .../boot/context/env/AliCloudProperties.java | 190 ++++++++++++++++++ .../OssContextAutoConfiguration.java | 10 +- .../RdsEndpointAutoConfiguration.java | 4 +- .../endpoint/AbstractRedisEndpoint.java | 4 +- .../SchedulerXContextAutoConfiguration.java | 25 ++- .../cloud/spring/boot/sms/SmsServiceImpl.java | 16 +- 7 files changed, 253 insertions(+), 21 deletions(-) diff --git a/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/autoconfigure/EdasContextAutoConfiguration.java b/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/autoconfigure/EdasContextAutoConfiguration.java index a27af78..6d8ef25 100644 --- a/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/autoconfigure/EdasContextAutoConfiguration.java +++ b/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/autoconfigure/EdasContextAutoConfiguration.java @@ -20,12 +20,14 @@ import com.alibaba.cloud.context.edas.AliCloudEdasSdkFactory; import com.alibaba.cloud.spring.boot.context.env.AliCloudProperties; import com.alibaba.cloud.spring.boot.context.env.EdasProperties; + import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; /** * @author xiaolongzuo @@ -39,8 +41,27 @@ public class EdasContextAutoConfiguration { @ConditionalOnMissingBean @ConditionalOnClass(name = "com.aliyuncs.edas.model.v20170801.GetSecureTokenRequest") public AliCloudEdasSdk aliCloudEdasSdk(AliCloudProperties aliCloudProperties, EdasProperties edasProperties) { - return AliCloudEdasSdkFactory.getDefaultAliCloudEdasSdk(aliCloudProperties, - edasProperties.getRegionId()); + AliCloudEdasSdk aliCloudEdasSdk = null; + String accessKey = null; + String secretKey = null; + + + if (!StringUtils.isEmpty(aliCloudProperties.getEdasAccessKey()) && !StringUtils.isEmpty(aliCloudProperties.getEdasSecretKey())) { + accessKey = aliCloudProperties.getAccessKey(); + secretKey = aliCloudProperties.getSecretKey(); + aliCloudProperties.setAccessKey(aliCloudProperties.getEdasAccessKey()); + aliCloudProperties.setSecretKey(aliCloudProperties.getSecretKey()); + } + + aliCloudEdasSdk =AliCloudEdasSdkFactory.getDefaultAliCloudEdasSdk(aliCloudProperties, edasProperties.getRegionId()); + + if (!StringUtils.isEmpty(aliCloudProperties.getEdasAccessKey()) && !StringUtils.isEmpty(aliCloudProperties.getEdasSecretKey())) { + aliCloudProperties.setAccessKey(accessKey); + aliCloudProperties.setSecretKey(secretKey); + } + + return aliCloudEdasSdk; + } } diff --git a/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/env/AliCloudProperties.java b/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/env/AliCloudProperties.java index b9200fe..a64953e 100644 --- a/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/env/AliCloudProperties.java +++ b/aliyun-spring-boot-starters/aliyun-context-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/context/env/AliCloudProperties.java @@ -17,7 +17,10 @@ package com.alibaba.cloud.spring.boot.context.env; import com.alibaba.cloud.context.AliCloudConfiguration; + +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.util.StringUtils; import static com.alibaba.cloud.spring.boot.context.env.AliCloudProperties.PROPERTY_PREFIX; @@ -46,6 +49,57 @@ public class AliCloudProperties implements AliCloudConfiguration { */ public static final String SECRET_KEY_PROPERTY = PROPERTY_PREFIX + ".secret-key"; + /** + * oss access_key + */ + public static final String OSS_ACCESS_KEY_PROPERTY = PROPERTY_PREFIX + ".oss.access-key"; + + /** + * oss secret-key + */ + public static final String OSS_SECRET_KEY_PROPERTY = PROPERTY_PREFIX + ".oss-secret-key"; + + /** + * rds access_key + */ + public static final String RDS_ACCESS_KEY_PROPERTY = PROPERTY_PREFIX + ".rds-access-key"; + + /** + * rds secret-key + */ + public static final String RDS_SECRET_KEY_PROPERTY = PROPERTY_PREFIX + ".rds-secret-key"; + + + /** + * redis access_key + */ + public static final String REDIS_ACCESS_KEY_PROPERTY = PROPERTY_PREFIX + ".redis-access-key"; + + /** + * redis secret-key + */ + public static final String REDIS_SECRET_KEY_PROPERTY = PROPERTY_PREFIX + ".redis-secret-key"; + + /** + * sms access_key + */ + public static final String SMS_ACCESS_KEY_PROPERTY = PROPERTY_PREFIX + ".sms-access-key"; + + /** + * sms secret-key + */ + public static final String SMS_SECRET_KEY_PROPERTY = PROPERTY_PREFIX + ".sms-secret-key"; + + /** + * edas access_key + */ + public static final String EDAS_ACCESS_KEY_PROPERTY = PROPERTY_PREFIX + ".edas-access-key"; + + /** + * edas secret-key + */ + public static final String EDAS_SECRET_KEY_PROPERTY = PROPERTY_PREFIX + ".edas-secret-key"; + /** * alibaba cloud access key. */ @@ -56,6 +110,61 @@ public class AliCloudProperties implements AliCloudConfiguration { */ private String secretKey; + /** + * alibaba cloud OSS access key. + */ + + private String ossAccessKey; + + /** + * alibaba cloud OSS secret key. + */ + private String ossSecretKey; + + /** + * alibaba cloud RDS access key. + */ + private String rdsAccessKey; + + /** + * alibaba cloud RDS secret key. + */ + private String rdsSecretKey; + + /** + * alibaba cloud Redis access key. + */ + private String redisAccessKey; + + /** + * alibaba cloud Redis secret key. + */ + private String redisSecretKey; + + /** + * alibaba cloud SMS access key. + */ +// @Value(SMS_ACCESS_KEY_PROPERTY) + private String smsAccessKey; + + /** + * alibaba cloud SMS secret key. + */ +// @Value(SMS_SECRET_KEY_PROPERTY) + private String smsSecretKey; + + + /** + * alibaba cloud Edas access key. + */ + private String edasAccessKey; + + /** + * alibaba cloud Edas secret key. + */ + private String edasSecretKey; + + @Override public String getAccessKey() { return accessKey; @@ -74,4 +183,85 @@ public void setSecretKey(String secretKey) { this.secretKey = secretKey; } + + public String getOssAccessKey() { + return StringUtils.isEmpty(ossAccessKey)? getAccessKey():ossAccessKey; + } + + public void setOssAccessKey(String ossAccessKey) { + this.ossAccessKey = ossAccessKey; + } + + public String getOssSecretKey() { + return StringUtils.isEmpty(ossSecretKey)? getSecretKey():ossSecretKey; + } + + public void setOssSecretKey(String ossSecretKey) { + this.ossSecretKey = ossSecretKey; + } + + public String getRdsAccessKey() { + return StringUtils.isEmpty(rdsAccessKey)? getAccessKey():rdsAccessKey; + } + + public void setRdsAccessKey(String rdsAccessKey) { + this.rdsAccessKey = rdsAccessKey; + } + + public String getRdsSecretKey() { + return StringUtils.isEmpty(rdsSecretKey)? getSecretKey():rdsSecretKey; + } + + public void setRdsSecretKey(String rdsSecretKey) { + this.rdsSecretKey = rdsSecretKey; + } + + public String getRedisAccessKey() { + return StringUtils.isEmpty(redisAccessKey)? getAccessKey():redisAccessKey; + } + + public void setRedisAccessKey(String redisAccessKey) { + this.redisAccessKey = redisAccessKey; + } + + public String getRedisSecretKey() { + return StringUtils.isEmpty(redisSecretKey)? getSecretKey():redisSecretKey; + } + + public void setRedisSecretKey(String redisSecretKey) { + this.redisSecretKey = redisSecretKey; + } + + public String getSmsAccessKey() { + return StringUtils.isEmpty(smsAccessKey)? getAccessKey():smsAccessKey; + } + + public void setSmsAccessKey(String smsAccessKey) { + this.smsAccessKey = smsAccessKey; + } + + public String getSmsSecretKey() { + return StringUtils.isEmpty(smsSecretKey)? getSecretKey():smsSecretKey; + } + + public void setSmsSecretKey(String smsSecretKey) { + this.smsSecretKey = smsSecretKey; + } + + public String getEdasAccessKey() { + return StringUtils.isEmpty(edasAccessKey)? getAccessKey():edasAccessKey; + } + + public void setEdasAccessKey(String edasAccessKey) { + this.edasAccessKey = edasAccessKey; + } + + public String getEdasSecretKey() { + return StringUtils.isEmpty(edasSecretKey)? getSecretKey():edasSecretKey; + } + + public void setEdasSecretKey(String edasSecretKey) { + this.edasSecretKey = edasSecretKey; + } + } diff --git a/aliyun-spring-boot-starters/aliyun-oss-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/oss/autoconfigure/OssContextAutoConfiguration.java b/aliyun-spring-boot-starters/aliyun-oss-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/oss/autoconfigure/OssContextAutoConfiguration.java index 54cea9c..3011848 100644 --- a/aliyun-spring-boot-starters/aliyun-oss-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/oss/autoconfigure/OssContextAutoConfiguration.java +++ b/aliyun-spring-boot-starters/aliyun-oss-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/oss/autoconfigure/OssContextAutoConfiguration.java @@ -53,12 +53,12 @@ public OSS ossClient(AliCloudProperties aliCloudProperties, OssProperties ossPro if (ossProperties.getAuthorizationMode() == AliCloudAuthorizationMode.AK_SK) { Assert.isTrue(!StringUtils.isEmpty(ossProperties.getEndpoint()), "Oss endpoint can't be empty."); - Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getAccessKey()), - "${alibaba.cloud.access-key} can't be empty."); - Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getSecretKey()), - "${alibaba.cloud.secret-key} can't be empty."); + Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getOssAccessKey()), + "${alibaba.cloud.oss-access-key} or ${alibaba.cloud.access-key} can't be empty."); + Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getOssSecretKey()), + "${alibaba.cloud.oss-secret-key} or ${alibaba.cloud.secret-key} can't be empty."); return new OSSClientBuilder().build(ossProperties.getEndpoint(), - aliCloudProperties.getAccessKey(), aliCloudProperties.getSecretKey(), + aliCloudProperties.getOssAccessKey(), aliCloudProperties.getOssSecretKey(), ossProperties.getConfig()); } else if (ossProperties.getAuthorizationMode() == AliCloudAuthorizationMode.STS) { Assert.isTrue(!StringUtils.isEmpty(ossProperties.getEndpoint()), diff --git a/aliyun-spring-boot-starters/aliyun-rds-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/rds/actuate/autoconfigure/RdsEndpointAutoConfiguration.java b/aliyun-spring-boot-starters/aliyun-rds-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/rds/actuate/autoconfigure/RdsEndpointAutoConfiguration.java index 479b406..0218691 100644 --- a/aliyun-spring-boot-starters/aliyun-rds-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/rds/actuate/autoconfigure/RdsEndpointAutoConfiguration.java +++ b/aliyun-spring-boot-starters/aliyun-rds-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/rds/actuate/autoconfigure/RdsEndpointAutoConfiguration.java @@ -52,8 +52,8 @@ public class RdsEndpointAutoConfiguration { @ConditionalOnMissingBean(IAcsClient.class) public IAcsClient iAcsClient(AliCloudProperties aliCloudProperties) { DefaultProfile profile = DefaultProfile.getProfile( - rdsProperties.getDefaultRegionId(), aliCloudProperties.getAccessKey(), - aliCloudProperties.getSecretKey()); + rdsProperties.getDefaultRegionId(), aliCloudProperties.getRdsAccessKey(), + aliCloudProperties.getRdsSecretKey()); IAcsClient client = new DefaultAcsClient(profile); return client; } diff --git a/aliyun-spring-boot-starters/aliyun-redis-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/redis/actuate/endpoint/AbstractRedisEndpoint.java b/aliyun-spring-boot-starters/aliyun-redis-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/redis/actuate/endpoint/AbstractRedisEndpoint.java index 5058cc6..5be8eae 100644 --- a/aliyun-spring-boot-starters/aliyun-redis-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/redis/actuate/endpoint/AbstractRedisEndpoint.java +++ b/aliyun-spring-boot-starters/aliyun-redis-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/redis/actuate/endpoint/AbstractRedisEndpoint.java @@ -49,11 +49,11 @@ public AliCloudProperties getAliCloudProperties() { } public String getAccessKey() { - return getAliCloudProperties().getAccessKey(); + return getAliCloudProperties().getRedisAccessKey(); } public String getSecretKey() { - return getAliCloudProperties().getSecretKey(); + return getAliCloudProperties().getRedisSecretKey(); } protected IAcsClient createIAcsClient(String regionId) { diff --git a/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/schedulerx/autoconfigure/SchedulerXContextAutoConfiguration.java b/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/schedulerx/autoconfigure/SchedulerXContextAutoConfiguration.java index b972dc8..e84a258 100644 --- a/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/schedulerx/autoconfigure/SchedulerXContextAutoConfiguration.java +++ b/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/schedulerx/autoconfigure/SchedulerXContextAutoConfiguration.java @@ -30,6 +30,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; /** * @author xiaolongzuo @@ -47,8 +48,28 @@ public SchedulerXClient schedulerXClient(AliCloudProperties aliCloudProperties, EdasProperties edasProperties, SchedulerXProperties scxProperties, AliCloudEdasSdk aliCloudEdasSdk) { - return AliCloudScxInitializer.initialize(aliCloudProperties, edasProperties, - scxProperties, aliCloudEdasSdk); + SchedulerXClient schedulerXClient = null; + String accessKey = null; + String secretKey = null; + + //replcea access key and secret key + if(!StringUtils.isEmpty(aliCloudProperties.getEdasAccessKey())&&!StringUtils.isEmpty(aliCloudProperties.getEdasSecretKey())) { + //need a wrapper to make replace edas ak and sk + accessKey = aliCloudProperties.getAccessKey(); + secretKey = aliCloudProperties.getSecretKey(); + aliCloudProperties.setAccessKey(aliCloudProperties.getEdasAccessKey()); + aliCloudProperties.setSecretKey(aliCloudProperties.getEdasSecretKey()); + } + schedulerXClient = AliCloudScxInitializer.initialize(aliCloudProperties, edasProperties, scxProperties, aliCloudEdasSdk); + + + //reset access key and secret key + if(!StringUtils.isEmpty(aliCloudProperties.getEdasAccessKey())&&!StringUtils.isEmpty(aliCloudProperties.getEdasSecretKey())) { + aliCloudProperties.setAccessKey(accessKey); + aliCloudProperties.setSecretKey(secretKey); + } + + return schedulerXClient; } } diff --git a/aliyun-spring-boot-starters/aliyun-sms-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/sms/SmsServiceImpl.java b/aliyun-spring-boot-starters/aliyun-sms-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/sms/SmsServiceImpl.java index a244c33..acccf2f 100644 --- a/aliyun-spring-boot-starters/aliyun-sms-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/sms/SmsServiceImpl.java +++ b/aliyun-spring-boot-starters/aliyun-sms-spring-boot-starter/src/main/java/com/alibaba/cloud/spring/boot/sms/SmsServiceImpl.java @@ -58,8 +58,8 @@ public SmsServiceImpl(AliCloudProperties aliCloudProperties, public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest) throws ClientException { - return sendSmsRequest(sendSmsRequest, aliCloudProperties.getAccessKey(), - aliCloudProperties.getSecretKey()); + return sendSmsRequest(sendSmsRequest, aliCloudProperties.getSmsAccessKey(), + aliCloudProperties.getSmsSecretKey()); } @Override @@ -91,8 +91,8 @@ public boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListen private boolean startReceiveMsg(String messageType, String queueName, SmsMessageListener messageListener) { - String accessKeyId = aliCloudProperties.getAccessKey(); - String accessKeySecret = aliCloudProperties.getSecretKey(); + String accessKeyId = aliCloudProperties.getSmsAccessKey(); + String accessKeySecret = aliCloudProperties.getSmsSecretKey(); boolean result = true; try { new DefaultAlicomMessagePuller().startReceiveMsg(accessKeyId, accessKeySecret, @@ -116,8 +116,8 @@ public SendBatchSmsResponse sendSmsBatchRequest( SendBatchSmsRequest sendBatchSmsRequest) throws ServerException, ClientException { - return sendSmsBatchRequest(sendBatchSmsRequest, aliCloudProperties.getAccessKey(), - aliCloudProperties.getSecretKey()); + return sendSmsBatchRequest(sendBatchSmsRequest, aliCloudProperties.getSmsAccessKey(), + aliCloudProperties.getSmsSecretKey()); } @Override @@ -139,8 +139,8 @@ public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request @Override public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request) throws ClientException { - return querySendDetails(request, aliCloudProperties.getAccessKey(), - aliCloudProperties.getSecretKey()); + return querySendDetails(request, aliCloudProperties.getSmsAccessKey(), + aliCloudProperties.getSmsSecretKey()); } } From 4f551578aaa33d4d0618470a8f7feaf61847b09a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=BE=E5=93=92?= Date: Tue, 30 Mar 2021 17:13:10 +0800 Subject: [PATCH 2/2] update versions and README.mds --- aliyun-spring-boot-dependencies/pom.xml | 20 +-- .../aliyun-fc-spring-boot-sample/README.md | 148 +++++++++++++++++- .../README-zh.md | 2 +- .../aliyun-oss-spring-boot-sample/README.md | 2 +- 4 files changed, 156 insertions(+), 16 deletions(-) diff --git a/aliyun-spring-boot-dependencies/pom.xml b/aliyun-spring-boot-dependencies/pom.xml index 9a05bdf..40691ff 100644 --- a/aliyun-spring-boot-dependencies/pom.xml +++ b/aliyun-spring-boot-dependencies/pom.xml @@ -23,15 +23,15 @@ - 4.5.0 - 1.0.5 - 3.1.0 - 2.44.0 + 4.5.19 + 1.0.11 + 3.11.3 + 3.15.2 2.1.6 - 1.1.8.6 - 1.1.0 - 2.1.5 - 2.4.4 + 1.1.9 + 2.1.0 + 2.16.0 + 2.5.10 1.0.5 @@ -125,12 +125,12 @@ com.aliyun aliyun-java-sdk-fc - 1.8.11 + 1.8.15 com.aliyun.fc.runtime fc-java-core - 1.3.0 + 1.4.0 com.aliyun.fc.runtime diff --git a/aliyun-spring-boot-samples/aliyun-fc-spring-boot-sample/README.md b/aliyun-spring-boot-samples/aliyun-fc-spring-boot-sample/README.md index 9835a31..41b5f6e 100644 --- a/aliyun-spring-boot-samples/aliyun-fc-spring-boot-sample/README.md +++ b/aliyun-spring-boot-samples/aliyun-fc-spring-boot-sample/README.md @@ -1,9 +1,148 @@ -## Alibaba Cloud Function Compute Sample Application +# Alibaba Cloud Function Compute Sample Application -### Test locally +## 安装 Fun + +Fun 提供了三种安装方式 + +* [通过 npm 包管理安装](#%e9%80%9a%e8%bf%87-npm-%e5%8c%85%e7%ae%a1%e7%90%86%e5%ae%89%e8%a3%85) —— 适合所有平台(Windows/Mac/Linux)且已经预装了 npm 的开发者。 +* [通过下载二进制安装](#通过下载二进制安装) —— 适合所有平台(Windows/Mac/Linux)。 +* [通过 Homebrew 包管理器安装](#%e9%80%9a%e8%bf%87-homebrew-%e5%8c%85%e7%ae%a1%e7%90%86%e5%99%a8%e5%ae%89%e8%a3%85) —— 适合 Mac 平台,更符合 MacOS 开发者习惯 + +### 通过 npm 包管理安装 + +安装它的方式是通过 npm: + +```shell +$ npm install @alicloud/fun -g +``` + +> 如果在 Linux/MacOS 下执行报 "Error: EACCES: permission denied" 错误,请加上 `sudo` 执行:`sudo npm install @alicloud/fun -g`。 + +> 如果安装过程较慢,可以考虑使用淘宝 NPM 源:`npm --registry=https://registry.npm.taobao.org install @alicloud/fun -g` + +安装完成之后。在控制终端输入 fun 命令可以查看版本信息: + +```shell +$ fun --version +3.6.1 +``` + +### 通过下载二进制安装 + +打开 [releases](https://github.com/aliyun/fun/releases) 页面,在最新的版本中选择一个对应平台的 release 压缩包链接,点击即可直接下载。 + +下载到本地后,解压,即可直接使用。 + +#### Windows 平台 + +1. 找到一个最新的发布版本(Release)下载 `fun-*-win.exe.zip` 文件(其中 * 表示版本号,如 v3.6.1)。 +2. 解压文件 `fun-*-win.exe.zip` 得到 `fun-*.win.exe` 文件,重名为 `fun.exe`。 +3. 讲 fun.exe 文件拷贝到系统 PATH 目录即可,比如:`C:\WINDOWS\System32` +4. 打开命令终端,执行 `fun.exe --version`,查看返回版本号以验证是否安装成功。 + +#### Linux 平台 + +打开 Terminal ,在 bash/zsh 中依次执行如下命令 + +```bash +# 设置版本,请把下面更新为 https://github.com/aliyun/fun/releases 页面的最新版本 +$ FUN_VERISON="v3.6.1" + +# 下载到本地 +$ curl -o fun-linux.zip https://gosspublic.alicdn.com/fun/fun-$FUN_VERSION-linux.zip + % Total % Received % Xferd Average Speed Time Time Time Current + Dload Upload Total Spent Left Speed +100 32.2M 100 32.2M 0 0 2606k 0 0:00:12 0:00:12 --:--:-- 2376k + +# 解压 zip 文件 +$ unzip fun-linux.zip +Archive: fun-v3.6.1-linux.zip + inflating: fun-v3.6.1-linux + +# 移到 PATH 目录 +$ mv fun-*-linux /usr/local/bin/fun + +# 验证版本 +$ fun --version +3.6.1 +``` + +##### MacOS 平台 + +打开 Terminal ,在 bash/zsh 中依次执行如下命令 + +```bash +# 设置版本,请把下面更新为 https://github.com/aliyun/fun/releases 页面的最新版本 +$ FUN_VERISON="v3.6.1" + +# 下载到本地 +$ curl -o fun-macos.zip https://gosspublic.alicdn.com/fun/fun-$FUN_VERSION-macos.zip + % Total % Received % Xferd Average Speed Time Time Time Current + Dload Upload Total Spent Left Speed +100 32.2M 100 32.2M 0 0 2606k 0 0:00:12 0:00:12 --:--:-- 2376k + +# 解压 zip 文件 +$ unzip fun-macos.zip +Archive: fun-v3.6.1-macos.zip + inflating: fun-v3.6.1-macos + +# 移到 PATH 目录 +$ mv fun-*-macos /usr/local/bin/fun + +# 验证版本 +$ fun --version +3.6.1 +``` + +### 通过 Homebrew 包管理器安装 + +对于 Mac 系统,还可以选择使用 homebrew 安装 Fun。 + +```bash +brew tap vangie/formula +brew install fun +``` + +## 安装 Docker(可选) + +如果你需要通过 Fun 进行依赖编译和安装、本地运行调试,涉及到 fun install/build/local 等命令的功能,那需要在您的开发环境下有 docker。 + +### Windows 平台 + +可以参考官方[教程](https://store.docker.com/editions/community/docker-ce-desktop-windows)。如果遇到网络问题,可以下载阿里云提供的 [Docker For Windows](http://mirrors.aliyun.com/docker-toolbox/windows/docker-for-windows/beta/)。 + +### MacOS 平台 + +可以参考官方[教程](https://store.docker.com/editions/community/docker-ce-desktop-mac?tab=description)。如果遇到网络问题,可以下载阿里云提供的 [Docker For Mac](http://mirrors.aliyun.com/docker-toolbox/mac/docker-for-mac/stable/)。 + +### Linux 平台 + +可以参考官方[教程](https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-repository)。如果遇到网络问题,可以通过阿里云 Docker CE 镜像源站[下载](https://yq.aliyun.com/articles/110806)。 + +### [更多平台参考](https://hub.docker.com/search/?type=edition&offering=community) + +### 配置 docker 镜像加速器 + +安装好 docker 之后,就可以使用 docker 下载镜像了。如果遇到网络问题,推荐配置 aliyun [镜像加速器](https://yq.aliyun.com/articles/29941)。 + +## 配置 + +在第一次使用 fun 之前需要先执行 fun config 进行配置,按照提示,依次配置 `Account ID`、`Access Key Id`、`Secret Access Key`、 `Default Region Name` 即可。其中 `Account ID`、`Access Key Id` 你可以从[函数计算控制台](https://fc.console.aliyun.com)首页的右上方获得,如下图所示。 + +![](https://img.alicdn.com/tfs/TB13J02wp67gK0jSZPfXXahhFXa-2424-1380.png) +![](https://img.alicdn.com/tfs/TB1cYuGwuH2gK0jSZJnXXaT1FXa-2424-1380.png) + + +## Test locally Make sure Docker is installed and started in your host. +Build Package: + +```bash +mvn clean package +``` + Run the function: ```bash @@ -16,7 +155,7 @@ Invoke the HTTP function: curl http://localhost:8000/2016-08-15/proxy/helloscf/fcspring -d 'hello world' ``` -### Deploy to Alibaba Cloud +## Deploy to Alibaba Cloud Package the application in root directory: @@ -36,12 +175,13 @@ Run the following command from the project root to deploy. fun deploy ``` +You should replace the ACCOUNT-ID.REGION_ID with your own information before run the command curl. Invoke the HTTP function: ```bash curl https://ACCOUNT-ID.REGION_ID.fc.aliyuncs.com/2016-08-15/proxy/helloscf/fcspring/ -d "hello world" ``` -### Tips +## Tips The configuration items of `template.yaml` refer [Serverless Application Model](https://github.com/alibaba/funcraft/blob/master/docs/specs/2018-04-03.md). \ No newline at end of file diff --git a/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README-zh.md b/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README-zh.md index fc9fe42..b88a127 100644 --- a/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README-zh.md +++ b/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README-zh.md @@ -11,7 +11,7 @@ ### 接入 OSS 在启动示例进行演示之前,我们先了解一下如何接入 OSS。 -**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKey、secretKey、endpoint 即可。** +**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKey、secretKey、endpoint、BUCKET_NAME 即可。** 1. 修改 pom.xml 文件,引入 aliyun-oss-spring-boot-starter。 diff --git a/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README.md b/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README.md index 6f69aa4..e1240e1 100644 --- a/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README.md +++ b/aliyun-spring-boot-samples/aliyun-oss-spring-boot-sample/README.md @@ -12,7 +12,7 @@ If your applications are Spring Boot applications and you need to use Alibaba Cl ### Connect to OSS Before we start the demo, let's learn how to connect OSS to a Spring Boot application. -**Note: This section is to show you how to connect to oss. The actual configurations have been completed in the following example, and you only need to specify your accessKey, secretKey and endpoint.** +**Note: This section is to show you how to connect to oss. The actual configurations have been completed in the following example, and you only need to specify your accessKey, secretKey, BUCKET_NAME and endpoint.** 1. Add dependency aliyun-oss-spring-boot-starter in the pom.xml file in your Spring Boot project.