nimbus java_Nimbus:一款用于构建 Java 无服务器应用程序的框架

Nimbus is a Java framework that allows for easy deployment and testing of serverless applications.

Installation

Nimbus is made available though maven and is hosted in the maven central repository.

First you need to add the nimbus-core dependency to your pom. This adds the annotation processor and local testing capabilities.

com.nimbusframework

nimbus-core

0.10

Next the deployment plugin needs to be added. Currently only AWS is supported, so the region parameter needs to be supplied to the plugin configuration.

com.nimbusframework

nimbus-deployment-maven-plugin

0.6

eu-west-1

target/generated-sources/annotations/

You also need to use the maven shade plugin to package your project into a shaded jar:

org.apache.maven.plugins

maven-shade-plugin

3.2.1

package

shade

target/functions.jar

Here the compiled jar will be placed at target/lambda.jar

Finally, an optional step is to create a nimbus.yml file in the top level of your project. This has only one parameter, projectName, that lets you customise the project name. For example:

projectName: nimbusExample

Caution: projectName needs to be alphanumeric.

Deployment Plugin Configuration Parameters

region - The AWS region that this project will be deployed to.

stage - The project stage that will be deployed to

shadedJarPath - The location where the shaded jar is found. Defaults to target/functions.jar.

compiledSourcePath - The location where compiled nimbus files are found. This will be in the compiled annotation sources. Defaults to target/generated-sources/annotations/ (Correct for default java projects, for other languages will likely change)

How to Deploy

To deploy to AWS you need to provide your AWS credentials. This can be done in three ways:

Environment variables–AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. The AWS SDK for Java uses the EnvironmentVariableCredentialsProvider class to load these credentials.

Java system properties–aws.accessKeyId and aws.secretKey. The AWS SDK for Java uses the SystemPropertiesCredentialsProvider to load these credentials.

The default credential profiles file– typically located at ~/.aws/credentials (location can vary per platform). For example:

[default]

aws_access_key_id = AKIAEXAMPLEKEY

aws_secret_access_key = s8sjhdf/sifys+EXAMPLEACCESSKEY

Then to deploy you need to package your project by running mvn package, and then deploy using mvn nimbus-deployment:deploy

This creates a new stack, and reports any new endpoints.

Sample application

Here we show the deployment of a simple HelloWorld application (assuming correct pom and nimbus.yml files)

public class HelloWorld {

@HttpServerlessFunction(path="helloWorld", method=HttpMethod.GET)

public String helloWorld() {

return "Hello World!";

}

}

Now, we run mvn package.

After this we run mvn nimbus-deployment:deploy. On a successful run we get this output:

[info] Beginning deployment for project: HelloWorld, stage: dev

[info] Creating stack

[info] Polling stack create progress

***************

[info] Stack created

[info] Uploading lambda file

[info] Uploaded file

[info] Uploading cloudformation file

[info] Uploaded file

[info] Updating stack

**********************

[info] Updated stack successfully, deployment complete

[info] Deployment completed

[info] Created REST API. Base URL is https://bq0za24ki8.execute-api.eu-west-1.amazonaws.com/dev

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值