- 浏览: 2543181 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
AMAZON and Lambda(2)Lambda with Java
Set up Eclipse
https://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/setup-install.html
I am using the J2EE version, and I am not working on Android Development, so I ignore the ADT part.
Install the AWS plugin https://aws.amazon.com/eclipse
After install the AWS plugin, then we can configure the credential
https://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/setup-credentials.html
Find my key/secret from here
https://console.aws.amazon.com/iam/home?#/home
Select [Users] —> [My Name] —> [Create Access Key], it will generates the Access Key ID and Secret access key
Add the AWS access key to eclipse
[References] —> [AWS Toolkit] —> Put my Value to Access Key ID and Secret Access Key
After the changes, you can see the changes under ~/.aws as well.
>cat ~/.aws/credentials
[default]
aws_access_key_id = xxxxxxxx
aws_secret_access_key = xxxxxxxx
[CarlKey]
aws_access_key_id=xxxxxxxx
aws_secret_access_key=xxxxxxxxx
Check some lambda example from here
>git clone https://github.com/markusklems/aws-lambda-java-example
Check LambdaForm project first
Check another project
>git clone https://github.com/eugenp/tutorials
>cd tutorials/aws
But I only need to check the aws part I think, Check the AWS part only, Import that directory as Maven Project
It seems to be a good example, I start to read the docs
http://www.baeldung.com/java-aws-lambda
maven jar plugin
https://www.jianshu.com/p/7a0e20b30401
This one should be the latest documents
Part 1
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html
Serverless Computing - developers do not have to deal with the servers.
Under this model, the server still fetch the code, deploy the codes and then run the codes, but the price will be times of execution and duration of the execution on AWS lambda.
Platform as a Service PAAS micro services
Function as a Service FAAS nano services
Part 2
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html?page=2
Part 3
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html?page=3
The first time we run the lambda, AWS needs to crate a container with your JAR file and deploy it to an EC2 instance. Once it is firstly deployed, the function will run very quickly.
It will be a very tiny java project with pom.xml as follow:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sillycat.lambda</groupId>
<artifactId>sillycat-lambda-java</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>sillycat-lambda-java</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The request input class can be defined in java as well WidgetResponse.java
package com.sillycat.lambda.model;
public class WidgetRequest
{
private String id;
...snip getter and setter...
}
The response object or the business POJO in java, Widget.java
package com.sillycat.lambda.model;
public class Widget
{
private String id;
private String name;
public Widget()
{
super();
}
public Widget( String id, String name )
{
super();
this.id = id;
this.name = name;
}
...snip..getter and setter...
}
One of the interface about the handler interface class, EchoWidgetHandler.java
package com.sillycat.lambda.handler;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.sillycat.lambda.model.Widget;
import com.sillycat.lambda.model.WidgetRequest;
public class EchoWidgetHandler implements RequestHandler<WidgetRequest, Widget>
{
@Override
public Widget handleRequest( WidgetRequest widgetRequest, Context context )
{
return new Widget( widgetRequest.getId(), "My Widget 3 " + widgetRequest.getId() );
}
}
We can directly build the jar and upload that to lambda.
>mvn clean compile package
Then you can find and upload the jar in target/sillycat-lambda-java-1.0.jar
On the console, the Runtime is Java 8, Handler is com.sillycat.lambda.handler.EchoWidgetHandler
The running test data is
{
"id": "Carl"
}
After run the result will display a JSON response
{
"id": "Carl",
"name": "superMy Widget 3 Carl"
}
The first run will be XXX ms, the next will be less than 1ms.
And we can directly deploy from our eclipse plugin as well.
[Upload the function to Lambda] — [Choose an existing Lambda function] Mine is testSqsToS3.zip.
If we unzip the zip file, we can see the
com directory with all the java classes.
lib directory with jar like aws-lambda-java-core-1.2.0.jar
If you add dependency there in pom.xml
It will put more jars there as well.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>
References:
https://docs.aws.amazon.com/zh_cn/lambda/latest/dg/use-cases.html
http://www.baeldung.com/java-aws-lambda
https://github.com/markusklems/aws-lambda-java-example/wiki/Getting-Started
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html
Set up Eclipse
https://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/setup-install.html
I am using the J2EE version, and I am not working on Android Development, so I ignore the ADT part.
Install the AWS plugin https://aws.amazon.com/eclipse
After install the AWS plugin, then we can configure the credential
https://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/setup-credentials.html
Find my key/secret from here
https://console.aws.amazon.com/iam/home?#/home
Select [Users] —> [My Name] —> [Create Access Key], it will generates the Access Key ID and Secret access key
Add the AWS access key to eclipse
[References] —> [AWS Toolkit] —> Put my Value to Access Key ID and Secret Access Key
After the changes, you can see the changes under ~/.aws as well.
>cat ~/.aws/credentials
[default]
aws_access_key_id = xxxxxxxx
aws_secret_access_key = xxxxxxxx
[CarlKey]
aws_access_key_id=xxxxxxxx
aws_secret_access_key=xxxxxxxxx
Check some lambda example from here
>git clone https://github.com/markusklems/aws-lambda-java-example
Check LambdaForm project first
Check another project
>git clone https://github.com/eugenp/tutorials
>cd tutorials/aws
But I only need to check the aws part I think, Check the AWS part only, Import that directory as Maven Project
It seems to be a good example, I start to read the docs
http://www.baeldung.com/java-aws-lambda
maven jar plugin
https://www.jianshu.com/p/7a0e20b30401
This one should be the latest documents
Part 1
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html
Serverless Computing - developers do not have to deal with the servers.
Under this model, the server still fetch the code, deploy the codes and then run the codes, but the price will be times of execution and duration of the execution on AWS lambda.
Platform as a Service PAAS micro services
Function as a Service FAAS nano services
Part 2
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html?page=2
Part 3
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html?page=3
The first time we run the lambda, AWS needs to crate a container with your JAR file and deploy it to an EC2 instance. Once it is firstly deployed, the function will run very quickly.
It will be a very tiny java project with pom.xml as follow:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sillycat.lambda</groupId>
<artifactId>sillycat-lambda-java</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>sillycat-lambda-java</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The request input class can be defined in java as well WidgetResponse.java
package com.sillycat.lambda.model;
public class WidgetRequest
{
private String id;
...snip getter and setter...
}
The response object or the business POJO in java, Widget.java
package com.sillycat.lambda.model;
public class Widget
{
private String id;
private String name;
public Widget()
{
super();
}
public Widget( String id, String name )
{
super();
this.id = id;
this.name = name;
}
...snip..getter and setter...
}
One of the interface about the handler interface class, EchoWidgetHandler.java
package com.sillycat.lambda.handler;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.sillycat.lambda.model.Widget;
import com.sillycat.lambda.model.WidgetRequest;
public class EchoWidgetHandler implements RequestHandler<WidgetRequest, Widget>
{
@Override
public Widget handleRequest( WidgetRequest widgetRequest, Context context )
{
return new Widget( widgetRequest.getId(), "My Widget 3 " + widgetRequest.getId() );
}
}
We can directly build the jar and upload that to lambda.
>mvn clean compile package
Then you can find and upload the jar in target/sillycat-lambda-java-1.0.jar
On the console, the Runtime is Java 8, Handler is com.sillycat.lambda.handler.EchoWidgetHandler
The running test data is
{
"id": "Carl"
}
After run the result will display a JSON response
{
"id": "Carl",
"name": "superMy Widget 3 Carl"
}
The first run will be XXX ms, the next will be less than 1ms.
And we can directly deploy from our eclipse plugin as well.
[Upload the function to Lambda] — [Choose an existing Lambda function] Mine is testSqsToS3.zip.
If we unzip the zip file, we can see the
com directory with all the java classes.
lib directory with jar like aws-lambda-java-core-1.2.0.jar
If you add dependency there in pom.xml
It will put more jars there as well.
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>
References:
https://docs.aws.amazon.com/zh_cn/lambda/latest/dg/use-cases.html
http://www.baeldung.com/java-aws-lambda
https://github.com/markusklems/aws-lambda-java-example/wiki/Getting-Started
https://www.javaworld.com/article/3210726/application-development/serverless-computing-with-aws-lambda.html
发表评论
-
Stop Update Here
2020-04-28 09:00 310I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 468NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 362Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 364Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 330Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 424Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 429Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 367Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 445VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 377Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 468NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 414Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 332Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 243GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 445GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 321GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 307Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 310Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 286Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 303Serverless with NodeJS and Tenc ...
相关推荐
在本文中,我们将深入探讨如何使用适用于Java的AWS SDK来调用AWS Lambda函数,并解析返回的响应。Lambda是Amazon Web Services(AWS)提供的一种事件驱动的计算服务,它允许开发者运行代码而无需预置或管理服务器。...
【标题】"Serverless Architectures with AWS" 是一个关于利用亚马逊Web服务(AWS)构建无服务器架构的主题。无服务器架构是一种云计算模型,其中开发者只需关注应用程序的代码,而无需关心运行代码所需的基础设施...
Device Catalog: Amazon Fire TV and Fire TV Stick Device Catalog: Samsung DeX Appendix A: CWAC Libraries Appendix B: Android 8.0 Appendix C: Android 9.0 Appendix D: Community Theater and the Appinars
Java_DynamoDB例子.zip是一个包含Java编程语言与Amazon DynamoDB交互示例的压缩包。DynamoDB是亚马逊云服务(AWS)提供的一款全托管的NoSQL数据库服务,它提供了高可伸缩性、高性能和低延迟的数据存储解决方案。这个...
AWS Lambda 是亚马逊提供的一种无服务器计算服务,它可以在没有预置或管理服务器的情况下运行代码。Lambda 会自动扩展应用程序以保持一致的响应时间,无论用户负载如何变化。通过 Lambda,开发者只需上传代码,...
指定源代码仓库、构建环境(通常为Java运行时环境,如Amazon Linux AMI with OpenJDK)和构建spec文件。 3. **配置构建spec文件**:在你的项目根目录下创建“buildspec.yml”文件,列出构建过程的各个阶段,如安装...
2. 负载均衡与弹性伸缩:结合Amazon EC2 Auto Scaling和Application Load Balancer,确保应用在高负载时能够自动扩展。 3. 安全与监控:利用AWS IAM进行权限管理,使用CloudWatch进行日志监控和报警。 总结,...
使用Java开发应用程序时,AWS提供了多种与Java兼容的服务和工具,如EC2(弹性计算云)用于运行Java应用,S3(简单存储服务)用于存储静态文件,RDS(关系数据库服务)支持MySQL、PostgreSQL等数据库,以及Lambda无...
1. **配置AWS SDK**:首先,我们需要下载并引入AWS的Java SDK,压缩包中的`aws-java-sdk`就是这个SDK。在Coldfusion项目中,将SDK的JAR文件添加到类路径中,以便能够调用其提供的API。 2. **创建S3客户端**:使用...
在本项目"springboot-withAWS"中,我们将深入探讨如何使用Spring Boot框架与Amazon Web Services (AWS)集成,以构建和部署独立的云服务。这个项目着重于利用AWS的多种服务来实现高效、可靠的后端解决方案。以下是...
实际执行所有这些操作的API :grinning_face_with_smiling_eyes: (可选)将图块下载到提供的S3存储桶中 (可选)响应SNS通知以连续检查所需的图块设定值Sentinel Eater可以在两种模式下运行,当前为HTTP和Amazon。...