Triggering Step Function from Java service running on EC2 - amazon-web-services

I've setup my State Machine in the AWS console (I'm using it as a asynchronous workflow platform to trigger a few lambdas). Anyway, I want to trigger state machine with some input from a java service running on an EC2 instance. But I can't find anyway to do this. In fact it looks like the only triggering mechanism is via cloudwatch? Is that right? That doesn't seem right?
Thanks any help would help

In the AWS SDK for Java you have both AWSStepFunctionsClient.startExecution() and AWSStepFunctionsAsyncClient.startExecutionAsync()

Related

On AWS, run an AWS CLI command daily

I have an AWS CLI invocation (in this case, to launch a configured EMR cluster to do some steps and then shut down) but I'm not sure how to go about running it daily.
I guess one way to do it is an EC2 micro instance running a cron job, or an ECS task in a micro that launches the command, but that all seems like it might be overkill. It looks like there's also a way to do it in Lambda, but rom what I can tell it'd be kludgy.
This doesn't have to be a good long-term solution, something that's suitable until I can do it right (Data Pipelines) would work just fine.
Suggestions?
If it is not a strict requirement to use the AWS CLI, you can use one of the AWS SDK instead to programmatically invoke Lambda.
Schedule a CloudWatch Rules using cron
When configured, the CloudWatch Rules will trigger a Lambda function
Implement a Lambda function that calls EMR using one of the supported SDKs (e.g. the EMR class in the AWS JavaScript SDK)
Make sure that you have the IAM configuration in place
Full example is available in the Schedule AWS Lambda Functions Using CloudWatch Events
Kludgy? Yes, configuration is needed, however if you take into account the amount of work required to launch EC2 / ECS (and make sure that it re-launches in the event of failure), I'd say it evens out.
Not sure about the whole task that you are doing, but to avoid doing it:
Manually
Avoid another set up for resources in AWS (as you mentioned)
I would create a simple job in a Continuous Integration (CI) server like jenkins,bamboo,circleci ..... (list can go on). I would assume that you might already have a CI server running, why not use it?

Implement a Lambda function to run commands via SSM

I have a run document in ssm to install some agents on the server.
Now, I wanted to automate this task by running these documents whenever a new instance is launched.
I want to achieve this through aws lambda(script to implement run commands upon launch of a new instance)
Any help would be appreciated !!!
Unfortunately this is a very broad questions, one that could not possibly be answered simply.
I would first suggest you decide which language you wish to write your lambda function in currently there are .NET, python, Node.js, Java and Go.
Node.js is a fairly easy language to start with as it's well supported and you can write it within the inline AWS code editor.
I would suggest looking at the template Node.js lambda functions that aws provides when creating a new lambda function within the console. This will help you see how that could be put together and the various ways that may be used. If you get the hang of these and find them easy enough to understand then you can look at the Node.js SSM api which should be available by default in the lambda runtime and try out running a few commands.
Of course if you're not competent in Node.js and primarily use another language then that's an entirely different question.
There are many resources and examples online for writing lambdas that can be found very easily.
Use a cloudwatch rule for this.
Create a cloudwatch rule for EC2 Instance State-change Notification and running state. Use lambda as the target and invoke the SSM command from lambda (via API) on the instance. The event will have the details you need like instance id. Hope you are familiar with AWS API's and how to use it. You will need a proper IAM role for your Lambda for this to work. Also, remember Cloudwatch events are region specific and can only invoke a lambda in the same region.

Alternative to scheduled tasks

I'm moving stuff from Azure to AWS, and the only thing I'm really gonna miss is the webjobs, where I can schedule command line jobs.
I know I can achieve somewhat the same with task scheduler or windows services, but I do also like the way webjobs shows logs and that stuff...
Do anybody know a tool like that, that can run windows command line apps on AWS?
Checkout AWS Lambda. It is a new service from AWS.
AWS Lambda, compute service that runs your code in response to events and automatically manages the compute resources for you, making it easy to build applications that respond quickly to new information.
Lambda vs WebJobs

How to deploy and Run Amazon Kinesis Application on Amazon Kinesis service

I am trying to understand how to deploy an Amazon Kinesis Client application that was built using the Kinesis client library (KCL).
I found this but it only states
You can follow your own best practices for deploying code to an Amazon EC2 instance when you deploy a Amazon Kinesis application. For example, you can add your Amazon Kinesis application to one of your Amazon EC2 AMIs.
which is not giving a broader picture to me.
These examples use an Ant script to run Java program. Is this the best practice to follow?
Also, I understand even before running the EC2 instances I need to make sure
The developed code JAR/WAR or any other format needs to be on the EC2 instance
The EC2 instance needs to have all the required environment like Ant setup in place already to execute the program.
Could someone please add some more detail on this?
Amazon Kinesis will be responsible for ingesting data, not running your application. You can run your application anywhere, but it is a good idea to run it in EC2, as you are probably going to use other AWS Services, such as S3 or DynamoDB (Kinesis Client Library uses DynamoDB for sharding, for example).
To understand Kinesis better, I'd recommend that you launch the Kinesis Data Visualization Sample. When you launch this app, use the provided CloudFormation template. It will create a stack with the Kinesis stream and an EC2 instance with the application, that uses Kinesis Client Library and is a fully working example to start from.
The best way I have found to host a consumer program is using EMR, but not as a hadoop cluster. Package your program as a jar, and place it in s3. Launch an emr cluster and have it run your jar. Using the data pipeline you can schedule this job flow to run at regular intervals. You can also scale an emr cluster, or use a actual EMR job to process the stream if you choose to get the high tech.
You can also use Beanstalk. I believe this article is highly useful.

Background Process in AWS

I am new to AWS and have a question about an application I'm trying to write. I have a bunch of data that sits within Amazon RDS. On a periodic basis, I would like a small snippet of code to run against this data and in certain situations have notifications sent where appropriate. Of all the AWS services, what is the best architecture for this?
Thanks
You could use a simple cron job running on an EC2 instance. The cron job could run a script (PHP, Perl, whatever) to go fetch the data and then do something with it (notify people, generate reports etc)
Does that help?
See here for details on getting started with a Linux instance: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html
You could achieve the same results using a Windows machine and Scheduled Tasks. Here's the getting started guide for Windows instances: http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/EC2Win_GetStarted.html
You can use Scheduled Lambda service driven by CloudWatch events. It acts as a resilient cron.