Reputation: 102
I created a simple API test to post a document. The endpoint needs to be authenticated using AWS access and secret key. Here's my API test code:
public static async Task<HttpResponseMessage> PostRequest(string requestUrl, dynamic json = null, byte[] file = null)
{
var credentials = new ImmutableCredentials(accessKey, secretKey, null);
var url= url.SetQueryParams(json);
var httpContent = new ByteArrayContent(file );
var response = await client.PostAsync(
postUrl,
httpContent,
regionName: regionName,
serviceName: serviceName,
credentials: credentials);
return response;
}
Currently these credentials are hard coded (not great, I know). With my CI pipeline, I'm using CircleCi and I have stored my AWS keys in the environment variable section. My question now is how can I access and implement these variables to my test code?
The idea on what I'm trying to do is that I don't want to hard code my AWS keys in source control.
Upvotes: 1
Views: 1003
Reputation: 2522
You can use CircleCI context to store the AWS keys and then specify the context in the CircleCI config. It will prevent keeping them in code.
Upvotes: 1
Reputation: 8573
I use circleci, but I don't use dot.net.
I have added AWS credentials as environment variables for the circleci project. After that, I don't include the credentials part of my nodejs code. the aws-sdk
for nodejs
will use the environment variables to get the credentials. I believe the behaviour should be same for dot.net based applications as well.
Hope this helps.
Reference: Serverless Framework deploy through CircleCI
Upvotes: 1