Is it possible to deploy Spring Cloud function to AWS Lambda Continuously.
I want to use gradle and bitbucket pipeline, or if there is any effective way I can use.
Should I use '@EnableFunctionDeployer' annotation? What is the best way?
Is it possible to deploy Spring Cloud function to AWS Lambda Continuously.
I want to use gradle and bitbucket pipeline, or if there is any effective way I can use.
Should I use '@EnableFunctionDeployer' annotation? What is the best way?
@EnableFunctionDeployer
will not do the task you are looking for. `
Annotation to be used on a Spring Boot application if it wants to deploy a jar file containing a function definition.
Below is example of how Spring-Cloud-Function-Deployer is using this annotation.
@SpringBootApplication
@EnableFunctionDeployer
public class FunctionApplication {
public static void main(String[] args) throws IOException {
new ApplicationBootstrap().run(FunctionApplication.class, args);
}
}
More info on EnableFunctionDeployer.
Although, I cannot seem to find a gradle
plugin which can do the deployment to AWS Lambda directly but it is easy to do it with maven
with many plugins and ways.
One Example - This AWS article has maven archetype which generates a code base with pom.xml which does direct deployment to AWS Lambda(using CloudFormation in background). Below is the plugin configuration which is being used to execute aws cloudformation
executable.
<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>
If you insist to be on gradle, probably one of the option is to execute maven deploy
command from gradle using gradle-maven-exec-plugin(need to test it though).
My personal opinion would be to build the jar using gradle/maven and deploy using serverless framework separating the deploy & build with different tools.
Example - https://gist.github.com/lobster1234/201fb83dc2847a1e2a106a098636bc1f
Let me know your thoughts.
Amazon provides a tool for continuous deployment called AWS CodePipeline.
You can use it on it's own to continuously deploy your application or you could migrate your function to an AWS Codestar project, it creates every resource needed for building and deploying your function.
The AWS Free tier offers one free active pipeline each month and Codestar is free, so you can check it out without incurring in any costs.