1

是否可以将 Spring Cloud 功能连续部署到 AWS Lambda。

我想使用 gradle 和 bitbucket 管道,或者如果有任何我可以使用的有效方法。

我应该使用“@EnableFunctionDeployer”注释吗?什么是最好的方法?

4

2 回答 2

2

@EnableFunctionDeployer不会做你正在寻找的任务。`

如果要部署包含函数定义的 jar 文件,则在 Spring Boot 应用程序上使用的注解。

下面是Spring-Cloud-Function-Deployer如何使用此注解的示例。

@SpringBootApplication
@EnableFunctionDeployer
public class FunctionApplication {

    public static void main(String[] args) throws IOException {
        new ApplicationBootstrap().run(FunctionApplication.class, args);
    }
}

有关 EnableFunctionDeployer 的更多信息。

https://cloud.spring.io/spring-cloud-static/Greenwich.RELEASE/multi/multi__deploying_a_packaged_function.html


虽然,我似乎找不到可以直接部署到 AWS Lambda 的插件,但是使用许多插件和方法gradle很容易做到这一点。maven

一个示例 -这篇AWS 文章具有 maven 原型,它使用pom.xml生成代码库,该代码库直接部署到 AWS Lambda(在后台使用 CloudFormation)。下面是用于执行aws cloudformation可执行文件的插件配置。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
        <execution>
            <id>sam-local-invoke</id>
            <phase>verify</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>sam</executable>
                <arguments>
                    <argument>local</argument>
                    <argument>invoke</argument>
                    <argument>-e</argument>
                    <argument>event.json</argument>
                </arguments>
                <skip>${skipLocalInvoke}</skip>
            </configuration>
        </execution>
        <execution>
            <id>sam-package</id>
            <phase>install</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>aws</executable>
                <arguments>
                    <argument>cloudformation</argument>
                    <argument>package</argument>
                    <argument>--region=${awsRegion}</argument>
                    <argument>--template-file=template.yaml</argument>
                    <argument>--output-template-file=target/sam.yaml</argument>
                    <argument>--s3-bucket=${s3Bucket}</argument>
                    <argument>--s3-prefix=${s3Prefix}</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>sam-deploy</id>
            <phase>deploy</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>aws</executable>
                <arguments>
                    <argument>cloudformation</argument>
                    <argument>deploy</argument>
                    <argument>--region=${awsRegion}</argument>
                    <argument>--template-file=target/sam.yaml</argument>
                    <argument>--stack-name=${stackName}</argument>
                    <argument>--capabilities=CAPABILITY_IAM</argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

如果您坚持使用 gradle,则可能一种选择是使用gradle-maven-exec-pluginmaven deploy从 gradle 执行命令(尽管需要对其进行测试)。

我个人的意见是使用 gradle/maven 构建 jar 并使用无服务器框架进行部署,将部署和构建与不同的工具分开。

示例 - https://gist.github.com/lobster1234/201fb83dc2847a1e2a106a098636bc1f

让我知道你的想法。

于 2019-07-03T02:18:24.917 回答
1

Amazon 提供了一个名为 AWS CodePipeline 的持续部署工具。
您可以单独使用它来持续部署您的应用程序,也可以将您的函数迁移到 AWS Codestar 项目,它会创建构建和部署函数所需的所有资源。
AWS 免费套餐每月提供一个免费的活动管道,Codestar 是免费的,因此您可以在不产生任何费用的情况下查看它。

于 2019-07-02T10:27:33.550 回答