Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade versions, support single-AK/SK #57

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions aliyun-spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

<!-- Aliyun dependencies' versions -->

<aliyun.sdk.version>4.5.0</aliyun.sdk.version>
<alicloud.context.version>1.0.5</alicloud.context.version>
<aliyun.oss.version>3.1.0</aliyun.oss.version>
<aliyun.sdk.edas.version>2.44.0</aliyun.sdk.edas.version>
<aliyun.sdk.version>4.5.19</aliyun.sdk.version>
<alicloud.context.version>1.0.11</alicloud.context.version>
<aliyun.oss.version>3.11.3</aliyun.oss.version>
<aliyun.sdk.edas.version>3.15.2</aliyun.sdk.edas.version>
<aliyun.schedulerx.client.version>2.1.6</aliyun.schedulerx.client.version>
<aliyun.sdk.mns.version>1.1.8.6</aliyun.sdk.mns.version>
<aliyun.java.sdk.dysmsapi>1.1.0</aliyun.java.sdk.dysmsapi>
<aliyun.r-kvstore.version>2.1.5</aliyun.r-kvstore.version>
<aliyun.sdk.rds.version>2.4.4</aliyun.sdk.rds.version>
<aliyun.sdk.mns.version>1.1.9</aliyun.sdk.mns.version>
<aliyun.java.sdk.dysmsapi>2.1.0</aliyun.java.sdk.dysmsapi>
<aliyun.r-kvstore.version>2.16.0</aliyun.r-kvstore.version>
<aliyun.sdk.rds.version>2.5.10</aliyun.sdk.rds.version>
<alicloud-context.version>1.0.5</alicloud-context.version>
</properties>

Expand Down Expand Up @@ -125,12 +125,12 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-fc</artifactId>
<version>1.8.11</version>
<version>1.8.15</version>
</dependency>
<dependency>
<groupId>com.aliyun.fc.runtime</groupId>
<artifactId>fc-java-core</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.aliyun.fc.runtime</groupId>
Expand Down
148 changes: 144 additions & 4 deletions aliyun-spring-boot-samples/aliyun-fc-spring-boot-sample/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:

Expand All @@ -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).
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
### 接入 OSS
在启动示例进行演示之前,我们先了解一下如何接入 OSS。

**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKey、secretKey、endpoint 即可。**
**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKey、secretKey、endpoint、BUCKET_NAME 即可。**

1. 修改 pom.xml 文件,引入 aliyun-oss-spring-boot-starter。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

}

}
Loading