AWS .NET SDK, AliasTarget record set issues - c#

EDIT
Solved, the solution is in the comments.
I'm trying to create a record set in AWS Route53 that targets an alias CloudFront distribution.
At the moment, I'm creating a new hosted zone with the desired domain (works fine).
Afterward, I'm taking the HostedZoneId from the response and trying to create a recordset that points to a CloudFront Distribution that has this domain in his CNAMEs. (If I only create the hosted zone using the API and then trying to create the record set manually it works fine and I can see the CDN Alias on the list).
I'm following this example from AWS Documentation -
var response = client.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest
{
ChangeBatch = new ChangeBatch {
Changes = new List<change> {
new Change {
Action = "CREATE",
ResourceRecordSet = new ResourceRecordSet {
AliasTarget = new AliasTarget {
DNSName = "d123rk29d0stfj.cloudfront.net",
EvaluateTargetHealth = false,
HostedZoneId = "Z2FDTNDATAQYW2" // Different Hosted Zone?
},
Name = "example.com",
Type = "A"
}
}
},
Comment = "CloudFront distribution for example.com"
},
HostedZoneId = "Z3M3LMPEXAMPLE" // Different Hosted Zone?
});
Why is the Alias Target HostedZoneId property and the outer HostedZoneId aren't the same??? shouldn't they both be the Id of the hosted zone created for the desired domain?
The error I receive is -
Tried to create an alias that targets d123rk29d0stfj.cloudfront.net., type A in zone Z3BW3XHLEBEA2Z, but the alias target name does not lie within the target zone
Thanks for reading, cheers

So... of course that once Iv'e decided to post my question I found an answer lol.
According to the documentation, CloudFront HostedZoneId value MUST be Z2FDTNDATAQYW2.
Hope it might help anyone in the future, thanks.

Related

C# AWS - How to determine AWS Region Endpoint dynamically in c#

I am connecting to AWS SecretManager, in which my code connects to specific region endpoint(below code)
AmazonSecretsManagerConfig config = new AmazonSecretsManagerConfig { RegionEndpoint = RegionEndpoint.USEast1 };
Now, I want to add one more new region RegionEndpoint.USEast2
I want this RegionEndpoint selection dynamically, based on the specific region request. Kindly help, How can I configure Multi Region in my C# Code?
Note: My app is running on Fargate and not on EC2 instance, so below solutions won't work:
client = Amazon.Util.EC2InstanceMetadata.Region.SystemName;
or
client = new Amazon&&&&Client(credentials, RegionEndpoint.GetBySystemName("us-east-1"));
You should be able to get the current region from reading the AWS_REGION environment variable as mentioned in this post: How can we determine the current region with AWS Fargate.

Add Value to Azure App Configuration using Pulumi

I created an App Configuration using Pulumi:
_configurationStore = new ConfigurationStore(appConfigurationName, new ConfigurationStoreArgs
{
ResourceGroupName = _resourceGroup.Name,
Location = _resourceGroup.Location,
Sku = "standard"
});
Now I am stuck adding values to it. The docs don't mention any method to read or write settings into my ConfigurationStore (or I simply cannot find it).
How can I store simple key/value-Pairs?
How can I store "links" to values from an existing keyvault? Do I simply create the connectionstring manually?
Adding key-values was introduced by Azure Resource Manager (ARM) just recently in the 2020-07-01-preview version and there's no "stable" API version with them yet. So, you should use that version to define key-values
new Pulumi.AzureNextGen.AppConfiguration.V20200701Preview.KeyValue("kv",
new Pulumi.AzureNextGen.AppConfiguration.V20200701Preview.KeyValueArgs
{
ResourceGroupName = _resourceGroup.Name,
ConfigStoreName = _configurationStore.Name,
KeyValueName = "key1",
Value = "value1",
});
You can read more in the docs: https://www.pulumi.com/docs/reference/pkg/azure-nextgen/appconfiguration/keyvalue/
Also, discussed in this issue: https://github.com/pulumi/pulumi-azure-nextgen/issues/62

PayPalAPIInterfaceServiceService and SetExpressCheckout config / credential information

I created an app in my business account on this page:
https://developer.paypal.com/developer/applications/
When I click on the app I created I see the following:
Sandbox account, Client ID, and Secret.
I am trying to call SetExpressCheckout… but the documentation is unclear and examples are all over the map.
Basically I’m seeing things like:
var request = new SetExpressCheckoutReq() { … };
var config = new Dictionary<string, string>()
{
{ "mode", "sandbox" }, // some variations of these values
{ "clientId", "fromAbovePage" },
{ "clientSecret", "fromAbovePage" },
{ "sandboxAccount", "fromAbovePage" },
{ "apiUsername", "IDontKnow" },
{ "apiPassword", "IDontKnow" },
{ "apiSignature", "IDontKnow" }
};
var service = new PayPalAPIInterfaceServiceService(config);
var response = service.SetExpressCheckout(request, new SignatureCredential(config["apiUsername"], config["apiPassword"], config["apiSignature"]));
Also, kind of weird that credentials go into both the PayPalAPIInterfaceServiceService and the actual SetExpressCheckout call.
What are (and where do I get) the correct values for the above config? (the request itself I have pretty much figured out)
Note: PayPal support told me that I need to use Reference Transactons in order to charge varying amounts over potentially varying times without subsequent user interaction, if that is relevant.
I would love to see examples of this with the most recent API's if anyone has that information as well.
Thank you.
SetExpressCheckout is a legacy NVP API
For sandbox, it uses credentials from the "Profile" of a sandbox account in https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Faccounts%2F
For live, https://www.paypal.com/api
ClientID/Secret credentials are used for the current v2/checkout/orders REST API, which at the moment does not have any public documentation for vaulting or reference transactions; it is for one time payments. You can find information for a server-side integration at https://developer.paypal.com/docs/checkout/reference/server-integration/
If you are using this REST API integration, create two routes --one for 'Set Up Transaction' and one for 'Create Transaction'. Then pair them with this approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

Get AWS caller Identity with C# SDK

When I execute this with the aws cli, i.ex. inside a fargate task, I can see the UserId that my application is going to use
aws sts get-caller-identity
with this output on the console
{
"Arn": "arn:aws:sts::643518765421:assumed-role/url_process_role/6ae81f92-66f3-30de-1eaa-3a7d1902bad9",
"UserId": "ARDYOAZLVOAQXTT5ZXTV4:4ea81f97-66f3-40de-beaa-3a7d1902bad9",
"Account": "692438514791"
}
I would like to get the same information but using the C# SDK. I tried with the methods exposed in this doc but I can see some account related details but not the UserId assigned.
So far I've tried with this but I cannot see any profile when running in a Fargate task.
var awsChain = new Amazon.Runtime.CredentialManagement.CredentialProfileStoreChain();
System.Console.WriteLine($"Found {awsChain.ListProfiles().Count} AWS profiles.");
My final goal is to get it and add to some task processed with Fargate to save a correlation Id in the database when something fails and easily find the Fargate log stream.
IAmazonSecurityTokenService will provide the same information when executed with .netcore. Notice that the above example will only work inside the AWS domain as the endpoint is not publicly available if testing from a development machine.
var getSessionTokenRequest = new GetSessionTokenRequest
{
DurationSeconds = 7200
};
var stsClient = hostContext.Configuration.GetAWSOptions().CreateServiceClient<IAmazonSecurityTokenService>();
var iden = stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest { }).Result;
System.Console.WriteLine($"A={iden.Account} ARN={iden.Arn} U={iden.UserId}");

Azure Custom Vision API returning different results than project portal?

I've create a custom vision project to recognise characters (A, B, C...).
What is interesting: if I upload an image of a character (in this case an "N") to the vision API portal it will tell me that it is 99.9% sure it is an "N":
If however I use the client libraries to predict the very same image, I'm getting 53% that it is a "W" and only 37% that it is an "N":
I double checked that the latest iteration is the published one
I double checked that I'm using the correct project ID
My endpoint is set to "https://westeurope.api.cognitive.microsoft.com" in the CustomVisionPredictionClient
The code to get the prediction on my client:
var client = new CustomVisionPredictionClient()
{
ApiKey = predictionKey,
Endpoint = endpoint
};
var result = await client.PredictImageAsync(Guid.Parse(projectId), imageStream).ConfigureAwait(false);
var prediction = result.Predictions.FirstOrDefault();
Where does this difference come from and how to fix because according to the tests I did by uploading images the results are close to 100% correct no matter which character image I upload?
UPDATE: I noticed that there was an update for the client libraries. They went from 0.12pre to 1.0stable. After the update the PredictImageAsync is gone and replaced with DetectImageAsync. This expected as an additional parameter a model name. I tried using the name of the iteration and after a while the method returns with an internal server error. So not sure what to try next.
The comment above pointed my into the right direction - thanks!
The new client library has got two methods ClassifyImage and DetectImage (and various variations of them) which replace the previously used ones including PredictImage which I was using with the preview version of the client library.
To classify an image (which is what I wanted to do) ClassifyImage should of course be used. The new code looks like this and delivers an almost 100% correct prediction:
var client = new CustomVisionPredictionClient()
{
ApiKey = predictionKey,
Endpoint = endpoint
};
var result = await client.ClassifyImageAsync(Guid.Parse(projectId), "Iteration12", imageStream).ConfigureAwait(false);
var prediction = result.Predictions.FirstOrDefault();
endpoint is the URL of the region the vision API is hosted in, in my case https://westeurope.api.cognitive.microsoft.com.
predictionKey is available on the CustomVision.AI site in your project, so is the projectId
The publishedName parameter is the name of the iteration to use (in my case "Iteration12"

Categories