2

我是亚马逊 kines 的新手,我想创建一个 Java 应用程序来将记录放入 kinesis,然后将我的 .class 放入 jmeter 以在 beanshell 示例中使用此代码。但是当我调用 putRecord 时,我得到了这个异常:

com.amazonaws.AmazonServiceException: User: arn:aws:iam::xxxxx:user/jmeter is not authorized to perform: kinesis:PutRecord on resource: arn:aws:kinesis:eu-central-1:xxxxx:stream/jmeter (Service: AmazonKinesis; Status Code: 400; Error Code: AccessDeniedException; Request ID: xxxxx-xxxx-11e4-a036-1d3ce7b07b9e)

java代码如下(现在我只是想连接到kinesis e放一个简单的记录,然后我放一个json数组):

import java.nio.ByteBuffer;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.kinesis.AmazonKinesisClient;
import com.amazonaws.services.kinesis.model.PutRecordRequest;
import com.amazonaws.services.kinesis.model.PutRecordResult;


public class Kinesis {
    private static AmazonKinesisClient kinesisClient;
    private static final String streamName="jmeter";
    public static void main(String[] args) {
        init();
        long createTime = System.currentTimeMillis();
        PutRecordResult putRecordResult;
        PutRecordRequest putRecordRequest = new PutRecordRequest();
        putRecordRequest.setStreamName(streamName);
        putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", createTime).getBytes()));
        putRecordRequest.setPartitionKey(String.format("partitionKey-%d", createTime));
        try{
         putRecordResult = kinesisClient.putRecord(putRecordRequest);
         System.out.printf("Successfully put record, partition key : %s, ShardID : %s, SequenceNumber : %s.\n",
                    putRecordRequest.getPartitionKey(),
                    putRecordResult.getShardId(),
                    putRecordResult.getSequenceNumber());
        }catch(Exception e){
            System.out.println(e);
        }

    }   


    private static void init() {
        /*
         * The ProfileCredentialsProvider will return your [default]
         * credential profile by reading from the credentials file located at
         * (~/.aws/credentials).
         */
        AWSCredentials credentials = null;
        String accessKey = "myaccesskey" ;
        String secretKey = "mysecretkey/xxxx" ;
        credentials = new BasicAWSCredentials(accessKey, secretKey);
        kinesisClient = new AmazonKinesisClient(credentials);
        kinesisClient.setEndpoint("kinesis.eu-central-1.amazonaws.com","kinesis", "eu-central-1");
        System.out.println("Starting application");
        }
}
4

0 回答 0