[英]How to connect to Amazon Kinesis Firehose in ASP.Net Core 2.2 Web Api Application
I am a beginner in AWS and I want to send a sample data to s3 bucket using Amazon Kinesis from ASP.Net Core 2.2 Web Api Application. 我是AWS的初学者,我想使用来自ASP.Net Core 2.2 Web Api应用程序的Amazon Kinesis将示例数据发送到s3存储桶。 But I am unable to send data.
但是我无法发送数据。 Below is what I have tried.
下面是我尝试过的。 Steps I did:
我执行的步骤:
Created an AWS account and then created one s3 bucket. 创建一个AWS账户,然后创建一个s3存储桶。
Created a Kinesis account and linked the s3 bucket to it. 创建一个Kinesis帐户,并将s3存储桶链接到该帐户。
3. In Main 3.在主要
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
Amazon.Util.ProfileManager.RegisterProfile("demo-aws-profile", "MyAccessKeyId", "MySecretKey");
}
Question 1: What am I suppose to pass in place of "demo-aws-profile"
? 问题1:我应该通过什么来代替
"demo-aws-profile"
? Can it be any random name? 可以是任何随机名称吗?
Question 2: Is there anything else is needed to connect to AWS? 问题2:还需要连接到AWS吗?
Code Snippet 代码段
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
var o = new
{
Message = "Hello World"
};
byte[] oByte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(o));
AmazonKinesisConfig config = new AmazonKinesisConfig();
config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
// QUESTION 3: DO I NEED TO SET ANY OTHER PROPERTY IN CONFIG??
var client = new AmazonKinesisClient(config);
try
{
using (MemoryStream ms = new MemoryStream(oByte))
{
PutRecordRequest requestRecord = new PutRecordRequest();
// QUESTION 4: What is this stream name???
requestRecord.StreamName = "test-stream";
requestRecord.Data = ms;
var response = client.PutRecordAsync(requestRecord);
response.Wait();
return Ok(new
{
seq = response.Result.SequenceNumber
});
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
return new string[] { "value1", "value2" };
}
I am getting an exception as System.Threading.Tasks.TaskCanceledException: A task was canceled.
我收到异常,原因是
System.Threading.Tasks.TaskCanceledException: A task was canceled.
PS: I am a beginner and I could have done any basic mistake, so please let me know if I should provide any further details. PS:我是一个初学者,我可能犯了任何基本错误,所以请告知我是否需要提供更多详细信息。 I still think that I am not able to communicate with Kinesis and hence to my s3 bucket.
我仍然认为我无法与Kinesis通信,因此无法与我的s3存储桶通信。 Am I doing something wrong or missing some set up here.
我是在做错什么还是在这里缺少设置?
Try passing in your AccessKeyId, SecretAccessKey, and Region directly to the constructor as a test (you don't ever want to hard code these in a real release). 尝试将您的AccessKeyId,SecretAccessKey和Region直接传递给构造函数作为测试(您永远都不想在实际发行版中对它们进行硬编码)。 Make sure the user associated with these credentials has a policy configured to allow access to Kinesis.
确保与这些凭据关联的用户具有配置为允许访问Kinesis的策略。
Also use async/await. 也可以使用async / await。
[HttpGet]
public async Task ActionResult<IEnumerable<string>> Get()
{
var o = new
{
Message = "Hello World"
};
byte[] oByte = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(o));
var client = new AmazonKinesisClient(<AccessKeyId>, <SecretAccessKey>, <Region>);
try
{
using (MemoryStream ms = new MemoryStream(oByte))
{
PutRecordRequest requestRecord = new PutRecordRequest();
// QUESTION 4: What is this stream name???
requestRecord.StreamName = <your Kinesis stream name>;
requestRecord.Data = ms;
var response = await client.PutRecordAsync(requestRecord);
return Ok(new
{
seq = response.Result.SequenceNumber
});
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
return new string[] { "value1", "value2" };
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.