How to write unit test cases for AWS Appsync - amazon-web-services

I've been using AWS appsync service. However, I'm not able to figure out a way to write unit test cases for the development I've been doing.
Please see if anyone can share any information in this regard.

Related

How can I keep unit testing in Unity after introducing security rules to firestore?

I am using cloud firestore + cloud functions + firestore auth to support my game.
I developed the main part of the app with unit tests in the app plus typescript tests for cloud functions. Now I want to add security rules to secure the data.
When I do so, requiring the calls to be authenticated, all my unit tests in unity (naturally) fails, as I do not authenticate a user but mocks them as data representation of the user in the db.
I want to keep using my unit tests in unity but still requiring the real db to demand authentication.
I have tried to look around for mock auth, or auth test environment, but found nothing except the library rules-unit-testing.
I see the content of it with specialized logic for mocking user, making me think that I am understanding this the wrong way by trying to do this in unity. My question is, How to continue to do game tests in unity, which requires interacting with the firestore server, while keeping security rules?
I am answering my own question after more time.
My analysis was that I ran into issues because I had coupled my code too tightly: server logic was on the client side and broke when introducing security rules. I decided to move logic to cloud functions and have only simple client side calls (sets, gets, updates, http functions).
So if someone runs into similar problems (architecture hampers use of best practices) I suggest to re-think the architecture. Feels obvious when writing...
Have fun coding all ^_^

Using OWASP ZAP (and tools of the same purpose) on AWS EC2

I am currently planning to do some web application vulnerability testing on an EC2 server with OWASP ZAP.
From my very quick google search, I found that AWS has stated that penetration testing services are allowed without approval (https://aws.amazon.com/security/penetration-testing/).
However, to double down, I am wondering if anyone in the community has done this without issue.
Thanks!!!
Yes, I frequently ran ZAP scans in AWS while I was at Mozilla. They were of course all against apps that I was permitted to test.
You should be fine unless someone complains - if they do that then Amazon are likely to send you a warning and then disable your account if you dont reply with a good explanation, or if it keeps happenning of course.

Advice on creating a SAM template for an application?

I am relatively new to infrastructure-as-code, and understand the basic ideas. I have recently been tasked with creating a SAM template for a rather large serverless application, and I just want to see if anyone has a little guidance or perhaps a suggestion on how I can achieve this. I am not sure if what I need to do is even possible within the SAM framework to be honest...
The application has a vue.js frontend, that is stored on s3, which calls API gateway, which calls lambda, which is connected to 3 dynamodb tables. Auth is all handled by Cognito.
Can I define and link these various microservices/components within SAM or cloudformation easily? Are there alternative solutions? Any resources to recommend (Obviously the documentation, but sometimes an example can be immensely useful)
Any help is much appreciated!

DynamoDB and Unit Testing .NET core

We are implementing DynamoDB data store. For our unit tests we have got that covered for Web.API, services, repository layers. However, I have not found any mocking frameworks/unit test for DynamoDB for .NET Core, only to implement the local DynamoDB (https://aws.amazon.com/blogs/aws/amazon-dynamodb-libraries-mappers-and-mock-implementations-galore/) Amazon indicates that it's best to run the local instance (Dynamo Local), however, this is not ideal for us, since we have Azure dev-ops pipelines in place. This causes other issues,like deleting tables for each test run, making sure the local db instance is running etc.
I was thinking of extending the DynamoDBclient, DynamoContext etc and then use these to simulate, however, this seems like a lot of work and I am not sure if it is worthwhile. Can anyone suggest an easier alternative or have come across a framework, or implemented a good unit testing framework for DynamoDB for .NET Core. We really don't want to go down the path to use the local DynamoDB on our build server.
Thanks in advance.

Using DynamoDB from CakePHP 3 installed to Elastic Beanstalk

I have installed CakePHP 3 using directions from this tutorial:
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/php-cakephp-tutorial.html
It is working perfectly and actually installation was quite easy. There is PHP, CakePHP, MySQL working and also I noticed that the newest AWS SDK as whole is installed in vendor directory. So I am fully set to use also DynamoDB as my data source. You might ask why I should use DynamoDb since I am already using MySQL/MarianDB, this is because we have an application that is already in production and it is using DynamoDB. But we should be able to write admin application using CakePHP in top of DynamoDB. This is not technical decision but coming from business side.
I found good tutorial written by StarTutorial how to use DynamoDB as session handler in CakePHP 3:
https://www.startutorial.com/articles/view/using-amazon-dynamodb-as-session-handler-in-cakephp-3
Well, there is not long way to using DynamoDB for putting data, getting data and doing scans, isn't there? Do you have any simple example how to do it, how to write data to DynamoDB or do scan?
I have also read the article:
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.PHP.html
and this is working fine, no problem. But I would like to all the advantages of the CakePHP 3, templating, security and so on, thousands of hours time saved with well written code and very fast to start coding for example admin console :)
Thank you,
You could create a Lambda function (in case you want to go serverless) or any other microservice to abstract communication with your DynamoDB. This will definitely simplify your PHP code. You may call Lambda functions directly (via API Gateway), or post messages to SQS for better decoupling. I would recommend the use of SQS -- you'll need some kind of microservice anyway to consume messages and deal with your DynamoDB in a CQRS fashion. Hope it helps!
Thank you for your answer, I was looking for a example how to use the AWS SDK for DynamoDB without creating more complexity to this environment as it is. This way I would have to create yet another layer without using the SDK that already exists. Can you please give wokring example how AWS SDK is used from CakePHP 3 so that it can use DynamoDB as a data source for its applications without losing it´s own resources an capabilities (MVC, security etc).
Thank you,
After a hard debug and found bugs I was able to get it working with only using AWS SDK in CakePHP 3.