Amazon Kinesis putRecord AmazonServiceException

时间:2015-05-05 09:18:47

标签: java authentication exception amazon-web-services amazon-kinesis

我是amazon 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");
        }
}

0 个答案:

没有答案