简体   繁体   English

如何在ASP.Net Core 2.2 Web Api应用程序中连接到Amazon Kinesis Firehose

[英]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: 我执行的步骤:

  1. Created an AWS account and then created one s3 bucket. 创建一个AWS账户,然后创建一个s3存储桶。

  2. 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.

相关问题 asp.net core 2.2+ web 应用程序上的多个表单 - Multiple forms on an asp.net core 2.2+ web application 如何测试我的 ASP.NET Core 2.2 Web API GET IActionResult 返回 Ok(object)? - How to test my ASP.NET Core 2.2 Web API GET IActionResult that returns Ok(object)? 如何将AzureAD和AzureADBearer添加到asp.net core 2.2 web api - How to add AzureAD AND AzureADBearer to asp.net core 2.2 web api 如何使用 ASP.NET Core Web API 2.2 进行分页和过滤器 - How to make pagination and filters with ASP.NET Core Web API 2.2 如何在 ASP.NET Core 2.2 API 中使用 Automapper - How to use Automapper with ASP.NET Core 2.2 API 一个使用 Azure AD B2C 的多个客户端 ID(应用程序 ID)的 ASP.NET Core 2.2 Web API 应用程序 - One ASP.NET Core 2.2 Web API app Using Multiple Client IDs (Application IDs) of Azure AD B2C ASP.NET 内核 WEB Api 连接到JS - ASP.NET Core WEB Api connect to JS 处理身份验证/授权:ASP.NET Core Web 应用程序 =&gt; ASP.NET Core Web API =&gt; SQL - Handling authentication/authorization: ASP.NET Core Web Application => ASP.NET Core Web API => SQL 将 LAN 上的设备连接到 ASP.NET 内核 Web API - Connect device on LAN to ASP.NET Core Web API 如何在 Asp.net 核心 web api 中使用图形 Api 连接到 Outlook 日历 - how to connect to outlook calendar using graph Api in Asp.net core web api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM