jeudi 15 octobre 2015

AWS Dynamo DB Object Mapper Error

I am trying to query my AWS Dynamo DB table "UserCreds" via swift code. I have first defined a class and then mapped it to Dynamo DB table. Then I am calling AWSDynamoDBQueryExpression() to search for a row on this table. but the program keeps crashing with following error:

"ViewController11viewDidLoadFS0_FT_T_L_11DDBTableRow dynamoDBTableName]: unrecognized selector sent to class 0x102ec3d40]"

I have also ensured that I have correct credentials setup in the AppDelegate file. Any insight into the reasons why this could be failing would be much appreciated. Thanks!

Below is what the code looks like:

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()


    class DDBTableRow :AWSDynamoDBObjectModel {

        var UserIdentifier:String?
        var UserFullName:String?


        class func dynamoDBTableName() -> String! {
            return "UserCreds"
        }

        class func hashKeyAttribute() -> String! {
            return "UserIdentifier"
        }

        class func rangeKeyAttribute() -> String! {
            return "UserFullName"
        }

        //MARK: NSObjectProtocol hack
        override func isEqual(object: AnyObject?) -> Bool {
            return super.isEqual(object)
        }

        override func `self`() -> Self {
            return self
        }
    }


    //SEARCH FOR A ROW
    let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()

    let queryExpression = AWSDynamoDBQueryExpression()
    queryExpression.indexName = "UserIdentifier-UserFullName-index"
    queryExpression.hashKeyAttribute = "UserIdentifier"
    queryExpression.hashKeyValues = "1234"
    queryExpression.scanIndexForward = true

    dynamoDBObjectMapper.query(DDBTableRow.self, expression: queryExpression).continueWithExecutor(AWSExecutor.mainThreadExecutor(), withBlock: { (task:AWSTask!) -> AnyObject! in
        if (task.error != nil) {
            print("Error: \(task.error)")

            let alertController = UIAlertController(title: "Failed to query a test table.", message: task.error.description, preferredStyle: UIAlertControllerStyle.Alert)
            let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: { (action:UIAlertAction) -> Void in
            })
            alertController.addAction(okAction)
            self.presentViewController(alertController, animated: true, completion: nil)
        } else {
            if (task.result != nil) {
                print(task.result)
            }
            print("Performing Segue")
        }
        return nil
    })

}




Query hash/range key and local secondary index

Is it possible to Query a DynamoDB table using both the hash & range key AND a local secondary index?

I have three attributes I want to compare against in my query. Two are the main hash and range keys and the third is the range key of the local secondary index.




How to sign AWS API request in Java

How can I sign an AWS API request in Java? I was able to find how to do this in PHP but cannot seem to find anything in Java. I would like to sign a request to ItemSearch.

Is there maybe a library or something?




WSGIPath error when deploying Flask project in AWS

I have simple blog built with Flask as you can see here. However, when I am trying to deploy it on AWS using Beanstalk, I keep getting the error message:

"ERROR: Your WSGIPath refers to a file that does not exist."

In the log, I find the error message as: "Target WSGI script not found or unable to stat: /opt/python/current/app/application.py"

I have my application.py and .elasticbeanstalk in the root folder of the project.

Does anyone have an idea of why?

Thanks in advance.




How to make NodeJS Server deployed on AWS cloud go live?

I am new to NodeJS. I have the following code for hello world.

var http = require("http");
http.createServer(function(request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World!\n I am the AWS cloud');
    }).listen(8081);
console.log('Server is running at http://127.0.0.1:8081');

This code is saved on my AWS cloud which runs an Ubuntu 14.04 instance. I have installed nodeJS on Ubuntu. When I run the code it works fine and displays the console log message, but when I open a web browser on a different machine and type http://Public-IP-Address:8081 it does not work.

Also when I stop the script by pressing Ctrl+c and then again execute it, it displays the following error message:

Server is running at http://127.0.0.1:8081
events.js:85
      throw er; // Unhandled 'error' event
        ^
Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11)
    at Server._listen2 (net.js:1156:14)
    at listen (net.js:1182:10)
    at Server.listen (net.js:1267:5)
    at Object.<anonymous> (/home/ubuntu/NodeJSscripts/hw.js:17:22)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

When I go back and change the port number and run the script again, it then runs again without throwing any error, but the web browser still doesn't connect to the server through it's public IP.




journald to Cloudwatch Logs

I'm a newbie to CentOS and wanted to know the best way to parse journal logs to CloudWatch Logs.

My thought processes so far are:

--Use FIFO to parse the journal logs and ingest this to Cloudwatch Logs, - It looks like this could come with draw backs where logs could be dropped if we hit buffering limits.

--Forward journal logs to syslog and send syslogs to Cloudwatch Logs --

The idea is essentially to have everything logging to journald as JSON and then forward this across to CloudWatch Logs.

What is the best way to do this? how have others solve this problem?

Many Thanks!




Maven cannot find java.util.Objects when using mvn shade plugin?

I'm following AWS lambda's "create a jar using mvn":

http://ift.tt/1METsk0

and some reason when I try to do either "mvn clean install" nor "mvn package" run properly. the project is using java 8.

Here's my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://ift.tt/IH78KX"
         xmlns:xsi="http://ift.tt/ra1lAU"
         xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/VE5zRx">
    <modelVersion>4.0.0</modelVersion>

    <groupId>lambda</groupId>
    <artifactId>test</artifactId>
    <packaging>jar</packaging>
    <version>0.0.0.1-SNAPSHOT</version>
    <name>lambda-test</name>

    <dependencies>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-core</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-lambda-java-events</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.jcraft</groupId>
            <artifactId>jsch</artifactId>
            <version>0.1.53</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.3.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

and my code:

package lambda.test;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.LambdaLogger;
import com.google.gson.Gson;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

import java.util.Objects;
import java.util.Properties;
import java.util.Vector;

public class Test {

    private static final Gson gson = new Gson();

    public static String myHandler(Tester tester, Context context) {
        LambdaLogger logger = context.getLogger();
        logger.log("received: " + tester);

        try {
            JSch jSch = new JSch();
            Session session = jSch.getSession(username, sftpHost, sftpPort);
            session.setPassword(password);

            Properties config = new Properties();
            config.put("StrictHostKeyChecking", "no");

            session.setConfig(config);
            session.connect(15000);

            ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
            channel.connect();

            channel.cd("Inbox");
            Vector<ChannelSftp.LsEntry> list = channel.ls(".");

            logger.log("the list ==> \n" + gson.toJson(list));
        } catch (Exception e) {
            e.printStackTrace();
            logger.log("the exception: " + e.getMessage());
        }

        return String.valueOf(tester);
    }

    public static class Tester {
        private final String name;
        private final Integer id;

        public Tester(String name, Integer id) {
            this.name = name;
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public Integer getId() {
            return id;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Tester tester = (Tester) o;
            return  Objects.equals(name, tester.name) &&
                    Objects.equals(id, tester.id);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name, id);
        }

        @Override
        public String toString() {
            return gson.toJson(this);
        }
    }
}