I'm currently using Grails 2.4.5 and used AmazonWebService plugin for grails 2.4.5
I'm trying to create a new recordset on route53 using this plugin.
On my BuildConfig.groovy I used this plugin fro aws web services.
compile ":aws-sdk:1.10.44"
I need your help guys regarding route53 change resource record sets.
I got an error below when I tried to change route53 resource record sets.
Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found more than one in Change with [Action=CREATE, Name=app.sample.com., Type=A, SetIdentifier=null] (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: 2ca80154-78a7-11e9-b5e7-f7bc7c79e5e6). Stacktrace follows:
Message: Invalid request: Expected exactly one of [AliasTarget, all of [TTL, and ResourceRecords], or TrafficPolicyInstanceId], but found more than one in Change with [Action=CREATE, Name=app.sample.com., Type=A, SetIdentifier=null] (Service: AmazonRoute53; Status Code: 400; Error Code: InvalidInput; Request ID: 2ca80154-78a7-11e9-b5e7-f7bc7c79e5e6)
This is my code.
import com.amazonaws.services.route53.AmazonRoute53Client
import com.amazonaws.services.route53.model.AliasTarget
import com.amazonaws.services.route53.model.Change
import com.amazonaws.services.route53.model.ChangeAction
import com.amazonaws.services.route53.model.ChangeBatch
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult
import com.amazonaws.services.route53.model.RRType
import com.amazonaws.services.route53.model.ResourceRecord
import com.amazonaws.services.route53.model.ResourceRecordSet
import grails.plugin.awssdk.AmazonWebService
import grails.transaction.Transactional
#Transactional
class AwsRoute53Service {
AmazonWebService amazonWebService
ChangeResourceRecordSetsResult changeRecordSet() {
AmazonRoute53Client route53Client = amazonWebService.route53
AliasTarget target = new AliasTarget('hostedZoneIDHere', 'app.sample.com.')
target.setEvaluateTargetHealth(true)
List<ResourceRecord> resourceRecords = new ArrayList<>()
resourceRecords.add(new ResourceRecord('dNSNameHere'))
ResourceRecordSet recordSet = new ResourceRecordSet('app.sample.com.', RRType.A)
recordSet.setAliasTarget(target)
recordSet.setResourceRecords(resourceRecords)
recordSet.setTrafficPolicyInstanceId('simple')
List<Change> changes = new ArrayList<>()
changes.add(new Change(ChangeAction.CREATE, recordSet))
ChangeBatch changeBatch = new ChangeBatch(changes)
ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest('hostedZoneIDHere', changeBatch)
return route53Client.changeResourceRecordSets(request)
}
}
Can you tell me what is the problem with the setup?
I would be glad if you can help me with my problem right now.
Thank you guys.
I already solve this problem. below is the working code.
import com.amazonaws.services.route53.AmazonRoute53Client
import com.amazonaws.services.route53.model.AliasTarget
import com.amazonaws.services.route53.model.Change
import com.amazonaws.services.route53.model.ChangeAction
import com.amazonaws.services.route53.model.ChangeBatch
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsRequest
import com.amazonaws.services.route53.model.ChangeResourceRecordSetsResult
import com.amazonaws.services.route53.model.RRType
import com.amazonaws.services.route53.model.ResourceRecord
import com.amazonaws.services.route53.model.ResourceRecordSet
import grails.plugin.awssdk.AmazonWebService
import grails.transaction.Transactional
#Transactional
class AwsRoute53Service {
private static final String DOMAIN_NAME_SERVER = "${System.env.DOMAIN_NAME_SERVER}"
private static final String HOSTED_ZONE_ID = "${System.env.HOSTED_ZONE_ID}"
AmazonWebService amazonWebService
ChangeResourceRecordSetsResult changeRecordSet() {
AmazonRoute53Client route53Client = amazonWebService.route53
GetHostedZoneResult hostedZoneResult = route53Client.getHostedZone(new GetHostedZoneRequest(HOSTED_ZONE_ID))
HostedZone hostedZone = hostedZoneResult.getHostedZone()
ResourceRecordSet resourceRecordSet = new ResourceRecordSet()
.withName('dNSName')
.withType(RRType.CNAME)
.withTTL(60)
.withResourceRecords([
new ResourceRecord().withValue(DOMAIN_NAME_SERVER)
])
ChangeResourceRecordSetsRequest request = new ChangeResourceRecordSetsRequest()
.withHostedZoneId(hostedZone.id)
.withChangeBatch(
new ChangeBatch()
.withChanges([
new Change()
.withAction(ChangeAction.CREATE)
.withResourceRecordSet(resourceRecordSet)
])
)
return route53Client.changeResourceRecordSets(request)
}
}
Related
I searched a lot today but all answers seem to be only in nodejs. I'm currently working on ktor application and I can't seem to find any way to upload images into MongoDB with KMongo.
You can use GridFS to store and retrieve binary files in MongoDB. Here is an example of storing an image, that is requested with the multipart/form-data method, in a test database:
import com.mongodb.client.gridfs.GridFSBuckets
import io.ktor.application.*
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.request.*
import io.ktor.response.*
import io.ktor.routing.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.litote.kmongo.KMongo
fun main() {
val client = KMongo.createClient()
val database = client.getDatabase("test")
val bucket = GridFSBuckets.create(database, "fs_file")
embeddedServer(Netty, port = 8080) {
routing {
post("/image") {
val multipartData = call.receiveMultipart()
multipartData.forEachPart { part ->
if (part is PartData.FileItem) {
val fileName = part.originalFileName as String
withContext(Dispatchers.IO) {
bucket.uploadFromStream(fileName, part.streamProvider())
}
call.respond(HttpStatusCode.OK)
}
}
}
}
}.start()
}
To make a request run the following curl command: curl -v -F image.jpg=#/path/to/image.jpg http://localhost:8080/image
To inspect stored files run db.fs_file.files.find() in the mongo shell.
There are a couple of examples on the AWS SDK how to get the credentials, e.g.:
https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/prog-services-sts.html
https://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingTempSessionTokenJava.html
But when I run these snippets I cannot import AWSSecurityTokenServiceClientBuilder:
// note that the AWS SDK is pretty brittle across versions.
import $ivy.`com.amazonaws:aws-java-sdk:1.7.4`
import $ivy.`org.apache.hadoop:hadoop-aws:2.7.3`
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.services.securitytoken.model.AssumeRoleRequest
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder
var clientRegion = "*** Client region ***";
var roleARN = "*** ARN for role to be assumed ***";
var roleSessionName = "*** Role session name ***";
var stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(new ProfileCredentialsProvider())
.withRegion(clientRegion)
.build()
var roleRequest = new AssumeRoleRequest()
.withRoleArn(roleARN)
.withRoleSessionName(roleSessionName)
var roleResponse = stsClient.assumeRole(roleRequest)
var sessionCredentials = roleResponse.getCredentials()
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder
^cmd16.sc:13: not found: value AWSSecurityTokenServiceClientBuilder
var stsClient = AWSSecurityTokenServiceClientBuilder.standard()
^Compilation Failed
Compilation Failed
scala version 2.11.12
spark version 2.3.4, that means that I am tight to hadoop-aws 2.7.3, which depends on aws-java-sdk 1.7.4 :/
AFAICS, this class is not part of the AWS Java SDK until version 1.11.0.
You have to instantiate the AWSSecurityTokenServiceClient class yourself instead, without using the builder.
Call this constructor:
val stsClient = new AWSSecurityTokenServiceClient(new ProfileCredentialsProvider())
stsClient.setRegion(clientRegion)
I am pretty new to testing with RestAssured and using the methods.
This is my code
package com.123.tests;
import com.jayway.restassured.response.Response;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.specification.RequestSpecification;
public class PersonPostTest {
#Test
public void RegistrationSuccessful()
{
RestAssured.baseURI ="https://reqres.in/api";
RequestSpecification request = RestAssured.given();
JSONObject obj = new JSONObject();
obj.put("name", "morpheus");
obj.put("job", "leader");
request.body(obj.toString());
Response response = request.post("/users");
int statusCode = response.getStatusCode();
Assert.assertEquals(statusCode, "201");
String successCode = response.jsonPath().get("SuccessCode");
Assert.assertEquals( "Got the correct code", successCode, "Success");
}
}
and everything seems to be good but I get this below error.
[RemoteTestNG] detected TestNG version 6.14.2
FAILED: RegistrationSuccessful
java.lang.AssertionError: expected [201] but found [201]
I don't seem to understand what the problem is. Any help would be appreciated. Thank you
The return type of getStatusCode() is Integer.
You are checking equality of statusCode which is Integer(201) with Object type. That is the issue here.
Try with below snippet. It works.
Response response = request.post("/users");
int statusCode = response.getStatusCode();
Assert.assertEquals(statusCode, 201);
Check for Object Types here:
Assert.assertEquals(statusCode, "201");
One is Integer and the other is String. That's the reason for failure. Make sure to convert them to the same type.
Replace the assertion with the below:
Assert.assertEquals(statusCode, new Integer(201));
I need to override the DS.Store.findQuery in Ember cli. that is no problem in itself.
The problem is importing the _findQuery method from the 'finder' file -- in that new app/store.js file
this._findQuery doesnt work
https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store.js
in the 'shimmed' component/ember-data
the prototype is
function ember$data$lib$system$store$finders$$_findQuery(adapter, store, typeClass, query, recordArray
Has anyone some advice on the required import statement.
here is some failed attempts
import DS from 'ember-data';
import Ember from 'ember';
//import _findQuery from 'ember-data/lib/system/store/finders'; NOPE
//import _findQuery from 'ember-data'; NOPE
export default DS.Store.extend({
findQuery: function(typeName, query) {
var type = this.modelFor(typeName);
var array = this.recordArrayManager
.createAdapterPopulatedRecordArray(type, query);
var adapter = this.adapterFor(type);
Ember.assert("You tried to load a query but you have no adapter (for " + type + ")", adapter);
Ember.assert("You tried to load a query but your adapter does not implement `findQuery`", typeof adapter.findQuery === 'function');
var x = _findQuery(adapter, this, type, query, array); // <-- URGH HERE
return promiseArray(x);
},
I'm not sure that you are able to import it in the way you describe, you could do it on the Adapter though.
You should be able to override it per Adapter, or if you want to do it everywhere, override on your application Adapter.
Like this
import DS from 'ember-data';
import Ember from 'ember';
export default DS.ActiveModelAdapter.extend({
findQuery (typeName, query) {
// do your stuff here
}
});
The following code works just fine...simply displaying some JSON in an unordered list:
import 'dart:html';
import 'dart:convert';
main() {
// Db db = new Db("mongodb://127.0.0.1/mongo_dart-showjson");
querySelector("#sample_text_id")
..onClick.listen(showJSON);
}
void reverseText(MouseEvent event) {
var text = querySelector("#sample_text_id").text;
var buffer = new StringBuffer();
for (int i = text.length - 1; i >= 0; i--) {
buffer.write(text[i]);
}
querySelector("#sample_text_id").text = buffer.toString();
}
void showJSON(MouseEvent event) {
var path = 'hcps.json';
var hcpDisplay = querySelector('#json_length_id');
HttpRequest.getString(path).then((String fileContents) {
List<String> hcpList = JSON.decode(fileContents);
for (int i = 0; i < hcpList.length; i++) {
hcpDisplay.children.add(new LIElement()..text = hcpList[i].toString());
}
});
}
However, when I add an import statement for mongo-dart, the JSON is not displayed, though I do not receive an error:
import 'dart:html';
import 'dart:convert';
import 'package:mongo_dart/mongo_dart.dart';
main() {
Db db = new Db("mongodb://127.0.0.1/mongo_dart-showjson");
querySelector("#sample_text_id")
..onClick.listen(showJSON);
}
...
The mongo_dart package has been added to pubspec.yaml as a dependency.
Does anyone have an idea as to why importing the mongo_dart package would cause the json text not to display, though there is no error? Thank you in advance.
As stated in package readme
mongo-dart is a server-side driver library for MongoDb implemented in
pure Dart
.
It cannot work at client side. Main reason for that - browsers do not have real sockets to connect to databases like mongodb, mysql, postgress and so on. You may look at some database with a RESTful API like CouchDB. Or you should use some middleware - for example objectory.
You could try
import 'package:mongo_dart/mongo_dart.dart' as mdb;
main() {
mdb.Db db = new mdb.Db("mongodb://127.0.0.1/mongo_dart-showjson");
to see if there is a conflict
You could also add a try/catch block
try {
mdb.Db db = new mdb.Db("mongodb://127.0.0.1/mongo_dart-showjson");
} catch(e) {
print(e)
}
sometimes exceptions are swallowed due to the use of zones (might not help here though) but I think it's worth a try.
It is possible that the package cache directory is corrupted.
You could try
pub cache repair