小编Sha*_*Ram的帖子

AWS使用JAVA从s3对象创建新文件获取错误

我有一个形状文件,我需要从我的 java 代码中读取形状文件。我使用下面的代码来读取形状文件。

public class App {
    public static void main(String[] args) {
        File file = new File("C:\\Test\\sample.shp");
        Map<String, Object> map = new HashMap<>();//
        try {
            map.put("url", URLs.fileToUrl(file));
            DataStore dataStore = DataStoreFinder.getDataStore(map);
            String typeName = dataStore.getTypeNames()[0];
            SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
            SimpleFeatureCollection collection = source.getFeatures();

            try (FeatureIterator<SimpleFeature> features = collection.features()) {
                while (features.hasNext()) {
                    SimpleFeature feature = features.next();
                    SimpleFeatureType schema = feature.getFeatureType();
                    Class<?> geomType = schema.getGeometryDescriptor().getType().getBinding();

                    String type = "";
                    if (Polygon.class.isAssignableFrom(geomType) || MultiPolygon.class.isAssignableFrom(geomType)) {

                        MultiPolygon geom = (MultiPolygon) feature.getDefaultGeometry();
                        type …
Run Code Online (Sandbox Code Playgroud)

java lambda amazon-s3 amazon-web-services geotools

5
推荐指数
1
解决办法
1800
查看次数

从Java Lambda调用AWS Step函数

我在aws中创建了一个step函数。我的状态机名称为“ TestStep”。用于迭代从1到1000的数字。

我创建了一个具有“ AWSStepFunctionsFullAccess”策略的IAM角色。

我创建了一个Java lambda来访问此步骤功能。我的代码如下。

 final StateMachine stateMachine = stateMachine().comment("Iterator State Machine Example").startAt("ConfigureCount")
             .state("ConfigureCount", taskState()
               .resource("arn:aws:lambda:us-east-1:ACCOUNTID:function:TestStep")
               .transition(end()))
       .build();
final AWSStepFunctions client = AWSStepFunctionsClientBuilder.defaultClient();
        client.createStateMachine(new CreateStateMachineRequest()
                                                  .withName("TestStep")
                                                  .withRoleArn("arn:aws:iam::ACCOUNTID:role/ROLENAME")
                                                  .withDefinition(stateMachine));
Run Code Online (Sandbox Code Playgroud)

但是我收到如下错误。请帮助我正确获取此信息。当我从java调用它时,应该触发step函数并开始工作...

在此处输入图片说明

amazon-web-services aws-lambda aws-step-functions

5
推荐指数
2
解决办法
3305
查看次数

如何将数据从 s3 存储桶读取到 Kinesis Stream

我是 Kinesis 的新手。我想从 s3 存储桶读取数据到 Kinesis 流。我创建了一个名为“mystream”的运动流。在我的项目中,每 3 个月都会将一条记录上传到 s3。同时我需要将记录读取到 kinesis 流。我已经创建了用于读取文件的 Lamda 并将其保存到 RDS 数据库实例中。我发现在 lambda 项目中有一个 kinesis 事件。这是做事的方式吗?请帮我得到这个。我不知道如何开始它和所有......如果有人可以帮助我会很棒......

amazon-s3 amazon-web-services amazon-kinesis

2
推荐指数
1
解决办法
8066
查看次数

帮助我正确获取log4j2

我是新手,可以使用AWS Java Lambda Cloud Watch实现log4j2。我需要自定义日志,而不是云监视日志。我正在使用step函数上传一个大尺寸的csv记录,因此内置的云手表会重复记录同一件事。所以我打算用我的java lambda添加log4j2。为此,我在pom.xml中添加了以下依赖项

    <dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-lambda-java-log4j2</artifactId>
    <version>1.0.0</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.8.2</version>
  </dependency>
Run Code Online (Sandbox Code Playgroud)

然后在src / main / resources下添加log4j2.xml。log4j2.xml如下所示

<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="com.amazonaws.services.lambda.runtime.log4j2.LambdaAppender">
  <Appenders>
    <Lambda name="Lambda">
      <PatternLayout>
          <pattern>%d{yyyy-MM-dd HH:mm:ss} %X{AWSRequestId} %-5p %c{1}:%L - %m%n</pattern>
      </PatternLayout>
    </Lambda>
  </Appenders>
  <Loggers>
    <Root level="debug">
      <AppenderRef ref="Lambda" />
    </Root>
  </Loggers>
</Configuration>
Run Code Online (Sandbox Code Playgroud)

之后,检查日志,我创建了一个aws java lambda项目,我的代码如下所示。

 package com.amazonaws.lambda.demo;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import com.amazonaws.services.lambda.runtime.events.S3Event;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.S3Object;

import com.amazonaws.services.stepfunctions.AWSStepFunctions;
import com.amazonaws.services.stepfunctions.AWSStepFunctionsClientBuilder;
import com.amazonaws.services.stepfunctions.model.StartExecutionRequest;

import …
Run Code Online (Sandbox Code Playgroud)

java amazon-web-services amazon-cloudwatch log4j2 amazon-cloudwatchlogs

2
推荐指数
1
解决办法
1195
查看次数