creating instances with volume DeleteOnTermination=true failing - aws-cloudformation

I have the cloud formation template like below. Here I want to make the volumes all DeleteOnTermination as true. To achieve this I have included the BlockDeviceMappings section as only that allows setting value for DeleteOnTermination.
But I am getting error:
Invalid value '/dev/sdf' for unixDevice. Attachment point /dev/sdf is already in use
What am I doing wrong?
Should I remove the /dev/sdf from volume section and keep it only in BlockDeviceMappings?
"Resources":{
"INSc42a7c2eed094a79acd851bdc9772a13":{
"Type":"AWS::EC2::Instance",
"Properties":{
"InstanceType":"t2.micro",
"BlockDeviceMappings":[
{
"DeviceName":"/dev/sda1",
"Ebs":{
"VolumeSize":"50",
"DeleteOnTermination":"true"
}
},
{
"DeviceName":"/dev/sdf",
"Ebs":{
"VolumeSize":"100",
"DeleteOnTermination":"true"
}
}
],
"ImageId":"ami-6871a115",
"KeyName":"${aws_key_pair.KP6a0efc01a84c4103b648b57b425b0ca2.key_name}",
"NetworkInterfaces":[
{
"AssociatePublicIpAddress":"true",
"DeviceIndex":"0",
"SubnetId":"subnet-07f722e24335cea6f",
"GroupSet":[
"sg-0ed40ed2e6af3db09"
]
}
],
"Volumes":[
{
"Device":"/dev/sdf",
"VolumeId":{
"Ref":"Volume67430dc919ab486a887388695720e574"
}
}
],
"Tags":[
{
"Key":"Name",
"Value":"jagaranteamvoltest"
},
{
"Key":"vid",
"Value":"c42a7c2e-ed09-4a79-acd8-51bdc9772a13"
}
]
}
},
"Alias60d46c3715ee4a72a4d3739b951bd4e0":{
"Type":"AWS::KMS::Alias",
"Properties":{
"AliasName":"alias/KmsKeyVolTest",
"TargetKeyId":{
"Ref":"KmsKey60d46c3715ee4a72a4d3739b951bd4e0"
}
}
},
"KmsKey60d46c3715ee4a72a4d3739b951bd4e0":{
"Type":"AWS::KMS::Key",
"Properties":{
"Description":"key description sample",
"KeyPolicy":{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"Allow access for Key Administrators",
"Effect":"Allow",
"Principal":{
"AWS":[
"${data.aws_caller_identity.current.arn}"
]
},
"Action":[
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:TagResource",
"kms:UntagResource",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion",
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:CreateGrant",
"kms:ListGrants",
"kms:DescribeKey",
"ec2:*"
],
"Resource":"*"
}
]
}
}
},
"Volume67430dc919ab486a887388695720e574":{
"Type":"AWS::EC2::Volume",
"DeletionPolicy":"Delete",
"Properties":{
"AutoEnableIO":"false",
"AvailabilityZone":"us-east-1a",
"Encrypted":"true",
"KmsKeyId":{
"Ref":"KmsKey60d46c3715ee4a72a4d3739b951bd4e0"
},
"Size":"15",
"VolumeType":"standard",
"Tags":[
{
"Key":"vid",
"Value":"67430dc9-19ab-486a-8873-88695720e574"
}
]
}
}
},
"Outputs":{
"caceedaacdbdca":{
"Description":"Instance ID",
"Value":{
"Ref":"INSc42a7c2eed094a79acd851bdc9772a13"
}
},
"dceeaadbbde":{
"Description":"KMS Id",
"Value":{
"Ref":"KmsKey60d46c3715ee4a72a4d3739b951bd4e0"
}
}
}
}

Keep only one /dev/sdf in your template. Either "AWS::EC2::Volume" or from BlockDeviceMappings Or Change the name for one drive. You can't keep two volumes with the same name.

Related

How to get dependencyGraphManifests of a particular branch only using github graphql

I'm trying to get dependencyGraphManifests of a particular branch only, such as the default branch, I'm not really sure if this is even possible.
Here is my full query:
query orgRepos {
organization(login: "octokit") {
id
repositories(
first: 2
orderBy: {field: CREATED_AT, direction: ASC}
) {
edges {
node {
defaultBranchRef {
name
repository {
url
name
dependencyGraphManifests(withDependencies: true) {
totalCount
edges {
node {
blobPath
dependencies {
nodes {
packageName
requirements
}
}
}
}
}
}
}
}
}
}
}
}
But the response returns every manifest file.
Here is a simplified response:
"node": {
"defaultBranchRef": {
"name": "main",
"repository": {
"url": "https://github.com/octokit/octokit.js",
"name": "octokit.js",
"dependencyGraphManifests": {
"totalCount": 7,
"edges": [
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/package-lock.json"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/package.json"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/docs/package.json"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/.github/workflows/release.yml"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/.github/workflows/test.yml"
}
},
{
"node": {
"blobPath": "/octokit/octokit.js/blob/main/.github/workflows/update-prettier.yml"
}
}
]
}
}
}
}
It also worth noting that some of the blobpaths return invalid paths, such as /octokit/octokit.js/blob/main/docs/package.json, which doesn't actually exists on the default branch(its on a different branch). Is this a bug?

mongodb loopup pipeline geoNear

I am running into an issue where I'm trying to grab some documents near the current document in a lookup. If I manually enter the lon/lat the following query will work but it fails with trying to use anything from the "let". How can I reference the location of the parent document in the geoNear in the lookup pipeline?
[
{
"$match":{
'assessed_improvement_value':{'$gt':500},
'sqft':{'$gt':500}
}
},
{
"$lookup":{
"from":"properties",
"let":{
'lon':{"$arrayElemAt":["$location.coordinates",0]},
'lat':{"$arrayElemAt":["$location.coordinates",1]},
},
'pipeline': [
{
"$geoNear": {
"near": { "type": "Point", "coordinates": [ "$$lon" , "$$lat" ] },
"distanceField": "distance",
"spherical": true
}
},
{"$limit":10}
],
"as":"comps",
}
},
{"$limit":10}
]
Update
The first method I posted was in fact a mess. I've now came up with a much cleaner solution. I hope this helps someone in the future
[
{
"$lookup":{
"from":"properties",
"let":{
'plon':{"$arrayElemAt":["$location.coordinates",0]},
'plat':{"$arrayElemAt":["$location.coordinates",1]},
},
'pipeline': [
{
"$addFields":{
"distance":{
"$function":{
"body":"""
function(plonRad,platRad, lonRad, latRad) {
var R = 6373.0;
var dlon = lonRad - plonRad;
var dlat = latRad - platRad;
if((dlon == 0) || (dlat == 0)) {
return 0;
}
var a = Math.pow(Math.sin(dlat / 2),2)+ Math.cos(platRad) * Math.cos(latRad) * Math.pow(Math.sin(dlon / 2),2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var dist = R * c;
return dist*0.621371;
}
""",
"args":[
{"$toDouble":{"$degreesToRadians":"$$plon"}},
{"$toDouble":{"$degreesToRadians":"$$plat"}},
{"$toDouble":{"$degreesToRadians":{"$arrayElemAt":["$location.coordinates",0]}}},
{"$toDouble":{"$degreesToRadians":{"$arrayElemAt":["$location.coordinates",1]}}}],
"lang":"js"
}
}
}
},
{
"$match":{
"distance":{"$gt":0}
}
},
{"$sort":{"distance":1}},
{"$limit":20}
],
"as":"comps",
}
}
]
I guess this is an old bug that was never fixed for whatever reason. This feels like a mess but it is a working solution. This manually calculates the distance in miles.
[
{
"$match":{
'assessed_improvement_value':{'$gt':500},
'sqft':{'$gt':500}
}
},
{
"$lookup":{
"from":"properties",
"let":{
'lon':{"$arrayElemAt":["$location.coordinates",0]},
'lat':{"$arrayElemAt":["$location.coordinates",1]},
},
'pipeline': [
{
"$addFields": {
'plonRad':{"$degreesToRadians":"$$lon"},
'platRad':{"$degreesToRadians":"$$lat"},
'lonRad':{"$degreesToRadians":{"$arrayElemAt":["$location.coordinates",0]}},
'latRad':{"$degreesToRadians":{"$arrayElemAt":["$location.coordinates",1]}},
}
},
{
'$addFields':{
"dlon":{
"$subtract":["$plonRad", "$lonRad"]
},
"dlat":{
"$subtract":["$platRad", "$latRad"]
},
}
},
{
"$addFields":{
'a':{
"$multiply":[
{
"$add":[
{
"$pow":[
{
"$sin":{
"$divide":["$dlat",2]
}
},
2
]
},
{
"$cos":"$platRad"
}
]
},
{
"$add":[
{
"$pow":[
{
"$sin":{
"$divide":["$dlon",2]
}
},
2
]
},
{
"$cos":"$latRad"
}
]
}
]
},
}
},
{
"$addFields":{
"c":{
"$atan2":[
{"$sqrt":"$a"},
{"$sqrt":{"$subtract":[1,"$a"]}}
]
}
}
},
{
"$addFields":{
"distance":{
"$divide":[
{"$multiply":[6373.0,"$c"]},
1609.34
]
}
}
},
{"$limit":10}
],
"as":"comps",
}
},
{"$limit":10}
]

The specified class for router or targets 'sap.f.routing.Router' is undefined

I am trying to use https://experience.sap.com/fiori-design-web/flexible-column-layout/ and got the following the error message:
The router configuration on the manifest file:
{
"_version":"1.9.0",
"sap.app":{
"id":"ch.mindustrie.ZMM_CLASSIFICATION",
"type":"application",
"i18n":"i18n/i18n.properties",
"applicationVersion":{
"version":"0.1.0"
},
"title":"{{appTitle}}",
"description":"{{appDescription}}",
"sourceTemplate":{
"id":"servicecatalog.connectivityComponentForManifest",
"version":"0.0.0"
},
"dataSources":{
"ZMM_CLASSIFICATION_SRV":{
"uri":"/sap/opu/odata/sap/ZMM_CLASSIFICATION_SRV/",
"type":"OData",
"settings":{
"odataVersion":"2.0",
"localUri":"localService/ZMM_CLASSIFICATION_SRV/metadata.xml"
}
}
}
},
"sap.ui":{
"technology":"UI5",
"icons":{
"icon":"",
"favIcon":"",
"phone":"",
"phone#2":"",
"tablet":"",
"tablet#2":""
},
"deviceTypes":{
"desktop":true,
"tablet":true,
"phone":true
},
"supportedThemes":[
"sap_hcb",
"sap_belize"
]
},
"sap.ui5":{
"handleValidation":true,
"rootView":{
"viewName":"ch.mindustrie.ZMM_CLASSIFICATION.view.App",
"type":"XML",
"async":true,
"id":"app"
},
"dependencies":{
"minUI5Version":"1.56.0",
"libs":{
"sap.ui.layout":{
},
"sap.ui.core":{
},
"sap.m":{
}
}
},
"contentDensities":{
"compact":true,
"cozy":true
},
"models":{
"i18n":{
"type":"sap.ui.model.resource.ResourceModel",
"settings":{
"bundleName":"ch.mindustrie.ZMM_CLASSIFICATION.i18n.i18n"
}
},
"Classification":{
"uri":"/sap/opu/odata/sap/ZMM_CLASSIFICATION_SRV/",
"type":"sap.ui.model.odata.v2.ODataModel",
"settings":{
"defaultOperationMode":"Server",
"defaultBindingMode":"OneWay",
"defaultCountMode":"Request"
},
"dataSource":"ZMM_CLASSIFICATION_SRV",
"preload":true
}
},
"resources":{
"css":[
{
"uri":"css/style.css"
}
]
},
"routing":{
"config":{
"routerClass":"sap.f.routing.Router",
"viewType":"XML",
"viewPath":"ch.mindustrie.ZMM_CLASSIFICATION.view",
"controlId":"idClassLayout",
"bypassed":{
"target":[
"master"
]
},
"async":true
},
"routes":[
{
"pattern":"",
"name":"search",
"target":[
"characteristic",
"search"
],
"layout":"TwoColumnsBeginExpanded"
},
{
"pattern":"search/{classnum}/{classtype}",
"name":"characteristic",
"target":[
"search",
"characteristic"
],
"layout":"TwoColumnsMidExpanded"
}
],
"targets":{
"search":{
"viewName":"Search",
"viewLevel":1,
"viewId":"search",
"controlAggregation":"beginColumnPages"
},
"characteristic":{
"viewName":"Characteristic",
"viewLevel":2,
"viewId":"characteristic",
"controlAggregation":"endColumnPages"
}
}
}
},
"sap.platform.abap":{
"uri":"/sap/bc/ui5_ui5/sap/zmm_classifi/webapp",
"_version":"1.1.0"
}
}
What does it not recognize sap.f.routing.Router? What am I doing wrong?
In order to make use of the router class "sap.f.routing.Router", the corresponding library sap.f needs to be preloaded.
In manifest.json section "sap.ui5" (for Component based apps):
"dependencies" : {
"libs": {
"sap.ui.core": {},
"sap.m": {},
"sap.f": {},
"sap.ui.layout": {}
}
}
In index.html otherwise:
<script id="sap-ui-bootstrap" src="..."
data-sap-ui-libs="sap.ui.core,sap.m,sap.f,sap.ui.layout"
data-sap-ui-async="true"
...
></script>
Keep in mind that the router class from sap.f is available as of UI5 1.46.
Press Ctrl+Shift+Left Alt+P or enter sap.ui.version in the browser console to see which UI5 core version the app is running with.

Retrieve json object in text file using powershell

I have 1000 number of JSON objects in text file. I want to retrieve only one JSON object for a particular duns number using PowerShell.
{
"organization":{
"duns":"024330410",
"dunsControlStatus":{
"operatingStatus":{
"description":"Active",
"dnbCode":9074
},
"isMarketable":false,
"isMailUndeliverable":false,
"isTelephoneDisconnected":null,
"isDelisted":false,
"subjectHandlingDetails":[
],
"fullReportDate":"2018-02-10"
},
"primaryName":"SRP Trucking LLC",
"multilingualPrimaryName":[
],
"tradeStyleNames":[
],
"websiteAddress":[
],
"telephone":[
],
"fax":[
],
"primaryAddress":{
"language":{
},
"addressCountry":{
"name":"United States",
"isoAlpha2Code":"US",
"fipsCode":"US"
},
"continentalRegion":{
"name":"North America"
},
"addressLocality":{
"name":"LAKE HAVASU CITY"
},
"minorTownName":null,
"addressRegion":{
"name":"Arizona",
"abbreviatedName":"AZ",
"fipsCode":"04"
},
"addressCounty":{
"name":"MOHAVE",
"fipsCode":"015"
},
"postalCode":"864035343",
"postalCodePosition":{
},
"streetNumber":null,
"streetName":null,
"streetAddress":{
"line1":"25 SOUTHWESTER LN",
"line2":null
},
"postOfficeBox":{
},
"latitude":34.488798,
"longitude":-114.301529,
"geographicalPrecision":{
"description":"Street Address Centroid",
"dnbCode":30257
},
"isRegisteredAddress":false,
"isResidentialAddress":null,
"statisticalArea":{
"cbsaName":"Lake Havasu City-Kingman AZ",
"cbsaCode":"29420",
"economicAreaOfInfluenceCode":"092",
"populationRank":{
"rankNumber":"7",
"rankDnBCode":10959,
"rankDescription":"100,000 to 249,999"
}
},
"locationOwnership":{
},
"premisesArea":{
"measurement":2915.0,
"unitDescription":"Square Foot",
"unitDnBCode":3848,
"reliabilityDescription":"Modelled",
"reliabilityDnBCode":9094
},
"isManufacturingLocation":null
},
"multilingualPrimaryAddress":[
],
"registeredAddress":{
},
"mailingAddress":{
},
"stockExchanges":[
],
"thirdPartyAssessment":[
],
"registrationNumbers":[
],
"industryCodes":[
{
"code":"484110",
"description":"General Freight Trucking, Local",
"typeDescription":"North American Industry Classification System 2017",
"typeDnBCode":30832,
"priority":1
},
{
"code":"1622",
"description":"Trucking",
"typeDescription":"D&B Hoovers Industry Code",
"typeDnBCode":25838,
"priority":1
},
{
"code":"4212",
"description":"Local trucking operator",
"typeDescription":"US Standard Industry Code 1987 - 4 digit",
"typeDnBCode":399,
"priority":1
},
{
"code":"42120000",
"description":"Local trucking, without storage",
"typeDescription":"D&B Standard Industry Code",
"typeDnBCode":3599,
"priority":1
},
{
"code":"E",
"description":"Transportation, Communications, Electric, Gas and Sanitary Services",
"typeDescription":"D&B Standard Major Industry Code",
"typeDnBCode":24657,
"priority":1
}
],
"businessEntityType":{
"description":"Unknown",
"dnbCode":0
},
"controlOwnershipDate":"2015",
"startDate":"2015",
"controlOwnershipType":{
},
"isAgent":null,
"isImporter":null,
"isExporter":null,
"numberOfEmployees":[
{
"value":1,
"informationScopeDescription":"Consolidated",
"informationScopeDnBCode":9067,
"reliabilityDescription":"Modelled",
"reliabilityDnBCode":9094,
"employeeCategories":[
],
"trend":[
]
},
{
"value":1,
"informationScopeDescription":"Individual",
"informationScopeDnBCode":9066,
"reliabilityDescription":"Modelled",
"reliabilityDnBCode":9094,
"employeeCategories":[
],
"trend":[
]
}
],
"financials":[
{
"financialStatementToDate":"2016-10-01",
"financialStatementDuration":null,
"informationScopeDescription":null,
"informationScopeDnBCode":null,
"reliabilityDescription":"Modelled",
"reliabilityDnBCode":9094,
"unitCode":"Single Units",
"accountantName":null,
"yearlyRevenue":[
{
"value":57815.0,
"currency":"USD",
"trend":[
]
}
]
}
],
"mostSeniorPrincipals":[
{
"givenName":"Debbie",
"familyName":"Pickering",
"fullName":"Debbie Pickering",
"namePrefix":null,
"nameSuffix":null,
"gender":null,
"jobTitles":[
{
"title":"Owner"
}
],
"managementResponsibilities":[
{
"description":"Owner",
"mrcCode":"A0A1"
}
]
}
],
"currentPrincipals":[
],
"socioEconomicInformation":{
"isMinorityOwned":null,
"isSmallBusiness":true
},
"isStandalone":true,
"corporateLinkage":{
}
}
}
PS direct have to JSON cmdlets which can serve your purpose:
Take the JSON string in a variable as $variable1, then use:
$variable1 | ConvertFrom-Json
and later you can use Convertto-Json to convert that to JSON also with where-object
Hope it helps. Just formed the answer from Tomalak

Finding multiple docs using same id not working, using meteor + react and mongoDB

How do I get the email address of the students in the same class_id, take it as there are more then 2 students in different class in the DB as well?
I have this but it return empty array []
Meteor.users.find({"course_learn_list.$.class_id": {$in: [classId]}},
{field: {"emails.address": 1}}
).fetch()
Collections
{
"_id": "LMZiLKs2MRhZiiwoS",
"course_learn_list": [
{
"course_id": "M8EiKfxAAzy25WmFH",
"class_id": "jePhNgEuXLM3ZCt98"
},
{
"course_id": "5hbwrfbfxAAzy2nrg",
"class_id": "dfbfnEuXLM3fngndn"
}
],
"emails": [
{
"address": "student1#gmail.com",
"verified": false
}
]
},
{
"_id": "JgfdLKs2MRhZJgfNgk",
"course_learn_list": [
{
"course_id": "M8EiKfxAAzy25WmFH",
"class_id": "jePhNgEuXLM3ZCt98"
},
{
"course_id": "5hbwrfbfxAAzy2nrg",
"class_id": "dfbfnEuXLM3fngndn"
}
],
"emails": [
{
"address": "student2#gmail.com",
"verified": false
}
]
}
I think you want:
Meteor.users.find({ "course_learn_list.class_id": classId },
{ "course_learn_list.$": 1, "emails.address": 1 }).fetch()
This should find the first instance in each course_learn_list array where the classId is your classId.
In this case you probably don't need to use a projection to get the right answer. Here's an example of extracting the verified email addresses using only the . operator in the selector:
const ids = ['jePhNgEuXLM3ZCt98', 'some-other-id'];
const emails =
Meteor.users.find({ 'course_learn_list.class_id': { $in: ids } })
.fetch()
.map(user => _.findWhere(user.emails, { verified: true }).address);
This works for me!
Meteor.publish("getMyClassStudents", function(classId) {
console.log("Publish getMyClassStudents")
var self = this
if (self.userId) {
var data = Meteor.users.find({
"course_learn_list.class_id": classId
}, {
"fields": {
"emails.address": 1
}
})
return data
}
else {
return self.ready()
}
})