2
votes

The issue I'm seeing is very much what happened here: https://forums.aws.amazon.com/thread.jspa?threadID=246123&tstart=0.

However, I have not worked with Powershell and would rather make this work without having to learn how to.

I have scheduled a task using Windows Schedule to run when an EC2 instance of Windows Server starts (started by a CloudWatch trigger). The task launches a Console Application that is supposed to pull data from a GoogleSheet, writes it as a RSS JSON file, and uploads it to an S3 bucket.

Everything works fine when the instance starts and +I log in+. The task runs, the console app runs, and the S3 bucket item is updated.

This does not work when (I see in the S3 bucket that the latest modification date is when I logged in last) not logged in, however, but I know that the task is running (shows in the history log of the scheduled task).

The instance has an IAM role attached for full S3 access.

The console app is a C# app. It uses the AmazonS3Config() method:

AmazonS3Config config = new AmazonS3Config();
            var awsAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
            var awsSecretKey = ConfigurationManager.AppSettings["AWSSecretKey"];
            AmazonS3Client client = new AmazonS3Client(awsAccessKey, awsSecretKey, RegionEndpoint.USEast1);
            tUtil = new TransferUtility(client);

In App.config I have the credentials for the AmazonS3Config() method:

  <appSettings>
    <add key="AWSAccessKey" value="****" />
    <add key="AWSSecretKey" value="****" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>

The task scheduler settings:

Task Settings

enter image description here

enter image description here

In addition to the above, I have carefully followed the instructions in this video. The app no longer checks for keys in the app.config file, they instead come from the EC2 instance itself. But this did not resolve the problem.

Suggestions?

3
does not work is too vague. - helloV
Where are you storing/getting the credentials for the aws account? - E.J. Brennan
The AWS account's Access & Secret keys are in the app.config file of the console app. - user

3 Answers

1
votes

AWS CLI's stores account profiles in user profile, when you logoff it can't load from user profile, so in your case logging in to system is a requirement with your approach. Which you can be changed, storing account profile at different place and loading it won't be problem, I suggest you to check here: https://docs.aws.amazon.com/cli/latest/userguide/cli-config-files.html

BTW, there are several check boxes in windows task scheduler in order to get your task running without logging in, please be aware of that. Additionally setting admin user to task is not enough for highest level permissions you need to check elevated privileges check box.

Regards...

0
votes

I would suggest adding logging using a library like NLog (https://github.com/NLog/NLog/wiki/Tutorial)

Add lots of info logging to your application at key areas of execution, and error output from any exceptions.

Once you have established exactly what part of the code is not working it'll be easier to give advice.

0
votes

As it turns out, since the app is a ClickOnce app, it has very special rules when being launched via the Task Scheduler. Essentially, point Task Scheduler to the app's shortcut...if you don't, task scheduler will tell you that the task completed successfully even if the app itself never ran.

See:

https://www.experts-exchange.com/questions/23704196/How-to-setup-a-scheduled-task-for-a-program-deployed-with-ClickOnce.html