AWS Lambda Java“无法连接到服务端点:”尽管为端点提供了.withEndpointConfiguration

时间:2020-03-29 05:01:46

标签: java amazon-web-services aws-lambda

请帮助我诊断错误消息“无法连接到服务端点:”。那是完整的错误信息。看起来好像找不到端点,但是正如您在下面看到的那样,我确实为端点提供了“ .withEndpointConfiguration”方法。

这是我的代码:

package xyz.bombchu;

import java.util.HashMap;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;

public class LambdaFunctionHandler implements RequestHandler<Object, String> {

    DynamoDB ddb;

    @Override
    public String handleRequest(Object input, Context context) {

        Regions REGION = Regions.AP_SOUTHEAST_2;

        HashMap<String, AttributeValue> item_values =
                new HashMap<String, AttributeValue>();

        String relativeTime = "02000001";
        item_values.put("dateTime", new AttributeValue().withN(relativeTime));
        item_values.put("cID", new AttributeValue("TEST"));

        AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.standard()
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("dynamodb.ap-southeast-2.amazonaws.com", "ap-southeast-2"))
                .withCredentials(new InstanceProfileCredentialsProvider())
                .withClientConfiguration(new ClientConfiguration())
                .build();

        try {
            ddb.putItem("myTableTest", item_values);
        } catch (Exception e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }
}

0 个答案:

没有答案