I am trying to import the vmdk to AWS EC2, but there seems to be no good java API documentation.
I have come across below flow, which should work,
DiskImageDetail id = new DiskImageDetail();
id.setFormat(DiskImageFormat.VMDK);
// id.setImportManifestUrl(importManifestUrl)
// TODO: set to 10GB e.g.
id.setBytes(80000000000L);
VolumeDetail volume = new VolumeDetail();
volume.setSize(80000000000L);
DiskImage i = new DiskImage();
i.setImage(id);
i.setVolume(volume);
i.setDescription("disk image");
List<DiskImage> listImages = new ArrayList<DiskImage>();
listImages.add(i);
ImportInstanceLaunchSpecification ls = new ImportInstanceLaunchSpecification();
ImportInstanceRequest ir = new ImportInstanceRequest();
ir.setDescription("Test");
ir.setDiskImages(listImages);
ir.setRequestCredentials(Connection.getAWSCredentials());
// ir.setGeneralProgressListener()
ir.setLaunchSpecification(ls);
// Some code to set
ImportVolumeRequest ivr = new ImportVolumeRequest();
//ivr.setSomeData();
AmazonEC2 ec2 = // set some connection
ec2.importInstance(ir);
ec2.importVolume(ivr);
But I am not sure about what values to pass, there's no sample code as well !
It can be done with the cmdlets but with Java I don't see anything hopeful.
Appreciate any help on this.
Thanks in advance
Related
I'm working on a project that used Uber Cadence Java Client. How can I get the list of open/closed workflows from the code? I can get it from CLI but not from java code.
Thank you.
WorkflowServiceTChannel cadenceService =
new WorkflowServiceTChannel(ClientOptions.defaultInstance());
ListOpenWorkflowExecutionsRequest request = new ListOpenWorkflowExecutionsRequest();
request.setDomain(DOMAIN);
=request.set...;
ListOpenWorkflowExecutionsResponse resp = cadenceService.ListOpenWorkflowExecutions(request);
ListClosedWorkflowExecutionsRequest request = new ListClosedWorkflowExecutionsRequest();
request.setDomain(DOMAIN);
=request.set...;
ListClosedWorkflowExecutionsResponse resp = cadenceService.ListClosedWorkflowExecutions(request);
// If you have advanced visibility
ListWorkflowExecutionsRequest request = new ListWorkflowExecutionsRequest();
request.setDomain(DOMAIN);
=request.setQuery(...);
ListWorkflowExecutionsResponse resp = cadenceService.ListWorkflowExecutions(request);
See how the cadenceService is used in this sample
Documentation about advanced visibility
I am trying to add CNAMEs for the existing Distribution in aws cloud front programmatically.
I have tried the following code, but it did not give any result. If someone knows how to do it programmatically. Please kind enough to mention it. Thank you
AmazonCloudFront cloudFront = AmazonCloudFrontAsyncClientBuilder.standard()
.withRegion(Regions.AP_EAST_1)
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(route53Manager.getAccessKey(), route53Manager.getSecretKey())))
.build();
GetDistributionConfigResult result = cloudFront.getDistributionConfig(
new GetDistributionConfigRequest("E1EJBNNYJZ6G34"));
Aliases aliases = new Aliases()
.withItems(subDomain)
.withQuantity(1);
DistributionConfig config = result.getDistributionConfig()
.withEnabled(true)
.withAliases(aliases);
It looks like you are missing the update distribution code and a few extra things. See the below code:
AmazonCloudFront cloudFront = AmazonCloudFrontAsyncClientBuilder.standard()
.withRegion(Regions.AP_EAST_1)
.withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(route53Manager.getAccessKey(), route53Manager.getSecretKey())))
.build();
//create the request
GetDistributionConfigRequest distributionConfigRequest = new GetDistributionConfigRequest("E1EJBNNYJZ6G34");
//submit the request and get the resulting config
GetDistributionConfigResult distributionConfigResult = cloudFront.getDistributionConfig(distributionConfigRequest);
Aliases aliases = new Aliases()
.withItems(subDomain)
.withQuantity(1);
DistributionConfig config = distributionConfigResult.getDistributionConfig()
.withEnabled(true)
.withAliases(aliases);
//create the update request
UpdateDistributionRequest updateDistributionRequest = new UpdateDistributionRequest(config, distributionConfigRequest.getId(), distributionConfigResult.getETag());
//submit the request to update the config
UpdateDistributionResult updateDistributionResult = cloudfront.updateDistribution(updateDistributionRequest);
//print output of result to console
System.out.println(updateDistributionResult);
The following code will create a new API KEY in AWS API Gateway. Just for fun, I also get an existing usage plan called "Basic" with an id of "1234"
For the life of me I can't find out how to take my newly created API Key and add the existing usage plan to it. This can be done manually on the web portal with the "Add to Usage Plan" button but I want to add my new user to a free plan.
BasicAWSCredentials awsCreds = new BasicAWSCredentials(aws_id, aws_key);
apiGateway = AmazonApiGatewayClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(Regions.US_EAST_1).build();
CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest();
createApiKeyRequest.setName("awesome company);
createApiKeyRequest.setEnabled(true);
createApiKeyRequest.setCustomerId("someid");
CreateApiKeyResult result = apiGateway.createApiKey(createApiKeyRequest);
GetUsagePlanRequest getUsagePlanRequest = new GetUsagePlanRequest();
getUsagePlanRequest.setUsagePlanId("1234");
GetUsagePlanResult getUsagePlanResult = apiGateway.getUsagePlan(getUsagePlanRequest);
Any AWS SDK experts know how to connect a usage plan to an api key?
Here's the solution to my post - the key type being "API_KEY" isn't documented anywhere, i found it in some random python sample :/ This creates a new user with an api key and adds them to a usage plan with the api gateway java sdk
BasicAWSCredentials awsCreds = new BasicAWSCredentials(aws_id, aws_key);
apiGateway = AmazonApiGatewayClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(Regions.US_EAST_1).build();
CreateApiKeyRequest createApiKeyRequest = new CreateApiKeyRequest();
createApiKeyRequest.setName("My awesome new user");
createApiKeyRequest.setEnabled(true);
createApiKeyRequest.setCustomerId(UUID.randomUUID().toString());
CreateApiKeyResult result = apiGateway.createApiKey(createApiKeyRequest);
GetUsagePlanRequest getUsagePlanRequest = new GetUsagePlanRequest();
getUsagePlanRequest.setUsagePlanId(BASIC_USAGE_PLAN_ID);
CreateUsagePlanKeyRequest createUsagePlanKeyRequest = new CreateUsagePlanKeyRequest()
.withUsagePlanId(BASIC_USAGE_PLAN_ID);
createUsagePlanKeyRequest.setKeyId(result.getId());
createUsagePlanKeyRequest.setKeyType("API_KEY");
apiGateway.createUsagePlanKey(createUsagePlanKeyRequest);
This should maybe be a comment instead, but I made an answer for readability (the key type is documented here).
// Client
AmazonApiGateway client = AmazonApiGatewayClientBuilder.standard().withRegion("my region here").build();
// Create new key
CreateApiKeyRequest keyReq = new CreateApiKeyRequest();
keyReq.setName("key name");
keyReq.setDescription("description");
keyReq.setEnabled(true);
CreateApiKeyResult keyRes = client.createApiKey(keyReq);
// Use existing plan
CreateUsagePlanKeyRequest planReq = new CreateUsagePlanKeyRequest();
planReq.setUsagePlanId("my usage plan id");
planReq.setKeyId(keyRes.getId()); // id from new key
planReq.setKeyType("API_KEY");
// add key to plan
client.createUsagePlanKey(planReq);
Note, this example is without a try-catch block
I'm currently working with the OPC UA Foundation Java Stack, without any additional SDK's.
I am unable to implement subscriptions with monitored items and to get the change notifications via the publish response. I am new to Java, any help regarding this would be really helpful. Thank you.
This is C#, not Java but you should be able to translate it. I hope it helps.
if (this.subscription == null)
{
this.subscription = new Opc.Ua.Client.Subscription(this.session.DefaultSubscription)
{
PublishingInterval = this.config.ReportingInterval,
TimestampsToReturn = TimestampsToReturn.Both
};
this.session.AddSubscription(subscription);
subscription.Create();
}
item = new MonitoredItem(subscription.DefaultItem)
{
StartNodeId = new NodeId(property.Identifier, this.config.NamespaceId),
SamplingInterval = this.config.SamplingInterval,
QueueSize = this.config.QueueSize,
};
subscription.AddItem(item);
subscription.ApplyChanges()
I'm trying to implement the tTorrent client into my program, I've looked at this link for an example (https://github.com/mpetazzoni/ttorrent/issues/16) and placed that code into the Download class of my program. Here is the code:
import statements:
import main.java.com.turn.ttorrent.client.Client;
import main.java.com.turn.ttorrent.client.SharedTorrent;
import main.java.com.turn.ttorrent.common.Torrent;
import main.java.com.turn.ttorrent.tracker.TrackedTorrent;
import main.java.com.turn.ttorrent.tracker.Tracker;
// Create tracker instance
Tracker tracker = new Tracker(InetAddress.getLocalHost());
// Load torrent file
File torrentFile = new File("/path/to/torrentFile.torrent");
// Create torrent instance
TrackedTorrent torrent = new TrackedTorrent(Torrent.load(torrentFile, null));
// Announce torrent
tracker.announce(torrent);
// Start the tracker
tracker.start();
torrentFile = new File(path + ".torrent");
File downloadDir = new File("/path/to/torrents_download_dir");//unsure
Client client = new Client(InetAddress.getLocalHost(), SharedTorrent.fromFile(torrentFile, downloadDir));
// Add client.share(); if you wish to share the torrent infinitely
client.run();
I'm getting this error message when I hover over load:
The method load(File, boolean) in the type Torrent is not applicable for the arguments (File, null)
I'm also unsure what I should place in File downloadDir. I'm still a beginner and if someone could point me in the right direction to putting this into my program that would be great. I'm still a beginner.
Torrent.load(torrentFile, null) wants a File object.
e.g
Torrent.load(new File(/foo/path.torrent), null)
Try to write your objects and method in a main Method
public static void main(String[] args) {
// Object 1;
// Object 2;
}