I have the following code:
this.nlb = new NetworkLoadBalancer(
this.parent,
this.id,
{
vpc: this.vpc,
vpcSubnets: {
subnets: subnets,
},
internetFacing: true,
}
);
const targetGroup = new NetworkTargetGroup(
this.parent,
`${this.id}-TG-${listenerPort}-${targetPort}`,
{
port: targetPort,
protocol: Protocol.TCP_UDP,
targetType: TargetType.INSTANCE,
vpc: this.vpc,
},
);
const listener = this.nlb.addListener(`${this.id}-TG-${listenerPort}`, {
port: listenerPort,
protocol: Protocol.TCP_UDP,
defaultTargetGroups: [
targetGroup,
]
});
It works as expected creating the network load balancer, the target group and the listener tied to the NLB.
What I cannot accomplish is adding this new TG to an existing AutoScaling Group.
The ASG is managed by a different project, but I need to add my TG to it.
If I try:
const asg = AutoScalingGroup.fromAutoScalingGroupName(
this.parent,
`${this.id}-ASG-${listenerPort}-${targetPort}`,
config.autoScalingGroup, // This has the name of the autoscaling group
);
const targetGroup = new NetworkTargetGroup(
this.parent,
`${this.id}-TG-${listenerPort}-${targetPort}`,
{
port: targetPort,
protocol: Protocol.TCP_UDP,
targets: [asg], // Add the imported ASG as target
targetType: TargetType.INSTANCE,
vpc: this.vpc,
},
);
It does not work because the imported SG does not offer the right methods.
Related
I have an scheduled job which is first polling my Mosquitto MQTT broker for Dynamic Security Plugin's clients by using 'listClients' command:
var options = {
port,
key,
cert,
username,
password,
rejectUnauthorized: false
};
const client = mqtt.connect('mqtts://mosquitto', options);
const MGMT_TOPIC = `$CONTROL/dynamic-security/v1`;
client.on('connect', function () {
schedule.scheduleJob('*/10 * * * * *', async function() { //Every 10 seconds
const payload = JSON.stringify({ commands: [{command: 'listClients'}] });
client.publish(MGMT_TOPIC, payload);
})
})
Then i have subscriber which listens for 'listClient' responses:
client.on("message", (topic, payload) => {
const response = JSON.parse(String(payload)); // { responses: [ { command: 'listClients', data: [Object] } ] }
if (response.responses) {
for (let r of response.responses) {
const command = r.command;
if (command === 'listClients') {
const data = r.data;
const clients = data.clients; // Array of strings
const newClients = ....
//LOGIC TO CHECK IF MY DB HAS HAS NEW CLIENTS
for (const newClient of newClients) {
const createClientPayload = JSON.stringify({
commands: [{
command: 'createClient',
username: newClient.username,
password: newClient.password
}]
});
client.publish(MGMT_TOPIC, createClientPayload);
}
}
}
}
});
Client creation is success, but when i get response from client creation from Mosquitto, it has payload like this:
{ responses: [ { command: 'createClient' } ] }
THIS IS NOT USEFULL!
I should also get username with this payload, because i need to set role for this user after it has been created?
Any help?
I could maybe use some variable to store old states? Sounds risky though...
I'm reading while coding a book(Pro MERN Stack 2nd Edition) and I get the error:
typeerror (0 graphql _1.is definition node) is not a function
in my GitCMD.
Click here to see the error in CMD
I have tried this, from another StackOverflow error but since Im using the apollo-server-express I think is kind of different.
Also tried installing older and newer package versions of the following:
"apollo-server-express": "^3.11.1"
and
"graphql": "^0.13.2",
The code looks like this:
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
let aboutMessage = "Issue Tracker API v1.0";
const typeDefs = `
type Query {
about: String!
}
type Mutation {
setAboutMessage(message: String!): String
}
`;
const resolvers = {
Query: {
about: ()=> aboutMessage,
},
Mutation: {
setAboutMessage,
},
};
function setAboutMessage(_, { message }) {
return aboutMessage = message;
}
const server = new ApolloServer({
typeDefs,
resolvers
});
const app = express();
app.use(express.static('public'));
server.applyMiddleware({ app, path: '/graphql' });
app.listen(3000, function () {
console.log('App started on port 3000');
});
this part alone:
const express = require('express');
const app = express();
app.use(express.static('public'));
app.listen(3000, function () {
console.log('App started on port 3000');
});
worked perfectly fine, but since I added the rest of it, it returns me the error :/
I updated my graphql to "graphql": "^16.6.0" and I got a different error: You must `await server.start()` before calling `server.applyMiddleware() so for that I needed to create an Async function, and inside the function I needed the name for my new server, the typeDefs, resolvers and then the await myserver.start():
and then the
myserver.applyMiddleware({ app, path: '/graphql' }); I dont know if thats well explained but here are the changes I made for the code to work:
const express = require('express');
const { ApolloServer } = require('apollo-server-express');
let aboutMessage = "Issue Tracker API v1.0";
const typeDefs = `
type Query {
about: String!
}
type Mutation {
setAboutMessage(message: String!): String
}
`;
const resolvers = {
Query: {
about: ()=> aboutMessage,
},
Mutation: {
setAboutMessage,
},
};
function setAboutMessage(_, { message }) {
return aboutMessage = message;
}
async function startServer(){
const server = new ApolloServer({
typeDefs,
resolvers,
});
await server.start();
server.applyMiddleware({ app, path: '/graphql' });
}
startServer();
const app = express();
app.use(express.static('public'));
app.listen(3000, function () {
console.log('App started on port 3000');
});
I didnt figured out on my own actually, I saw a post in Qiita about the same issue: Qiita same error URL.
I'm trying to call my solana contract from my frontend app.
Even though I added the baseAccount. Solana complains it's not added. Whats going on?
const baseAccount = Keypair.generate()
async function createNFT({ nftPrice, nftRoyalty, nftInfo }) {
// console.log('image', image)
// const added = await client.add(image)
// console.log(
// '`https://ipfs.infura.io/ipfs/${added.path}`',
// `https://ipfs.infura.io/ipfs/${added.path}`
// )
const provider = await getProvider()
const program = new Program(idl, programID, provider)
const price = new BN(nftPrice * 10 ** 9)
const result = await program.rpc.mintNft(
wallet.publicKey,
price,
nftRoyalty,
wallet.publicKey,
nftInfo,
{
accounts: {
baseAccount: baseAccount.publicKey,
user: provider.wallet.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [baseAccount],
}
)
console.log('result', result)
}
I'm creating multiple SQS queues, and I want to add a Lambda trigger after the queues are created. I'm getting an error (see below) when I do the cdk synth command.
I'm using the version 1.130 of aws-cdk and the packages are all the same version (1.130.0)
Error with build TypeError: Cannot read property 'scopes' of undefined
Looking at the stack trace error it fails at the lambdaFunction.addEventSource section.
I'm following the CDK documentation (https://docs.aws.amazon.com/cdk/api/v1/docs/aws-lambda-event-sources-readme.html) and based on that I think I'm following the right steps.
Below is the code I'm using:
const cdk = require(`#aws-cdk/core`);
const sqs = require(`#aws-cdk/aws-sqs`);
const { SqsEventSource } = require(`#aws-cdk/aws-lambda-event-sources`);
const lambda = require(`#aws-cdk/aws-lambda`);
const fs = require(`fs`);
const { env } = require(`process`);
class PVInfraSQSTopic extends cdk.Construct {
constructor(scope, id, props) {
super(scope, id, props);
const buildEnvironment = JSON.parse(fs.readFileSync(`./config/`+JSON.parse(env.CDK_CONTEXT_JSON).config+`.json`, `utf8`));
const sqsDLQ = buildEnvironment.sqsDeadLetterQueue;
const lambdas = buildEnvironment.sqsLambdaTrigger;
const sqsQueues = buildEnvironment.sqsQueues;
const alias = buildEnvironment.alias;
const region = buildEnvironment.region;
const awsAccount = buildEnvironment.awsAccount;
const queueName = `sqs-queue`;
// Create Dead Letter Queue.
const dlq = new sqs.Queue(this, `SQSBuild`, {
queueName: sqsDLQ
});
// Create queues and configure dead letter queue for said queues.
sqsQueues.map((item) => {
new sqs.Queue(this, `queue-${item}`, {
queueName: `${item}`,
deadLetterQueue: {
maxReceiveCount: 3,
queue: dlq
}
});
});
// Add SqsEventSource (Lambda Triggers) to new SQS queues
const lambdaFunction = lambda.Function.fromFunctionAttributes(this, `function`, {
functionArn: `arn:aws:lambda:${region}:${awsAccount}:function:${lambdas}:${alias}`
});
lambdaFunction.addEventSource(new SqsEventSource(queueName, {
batchSize: 10
}));
}
}
module.exports = { PVInfraSQSTopic };
The lambda already exists, so that is why I'm not creating it as part of this stack.
Your first problem is that you are passing the SqsEventSource constructor a string (queueName), when it requires an IQueue.
It still won't synth, through. You also need to give CDK more information about your existing lambda, namely the lambda's IAM role.
Here's a minimal working example. I am importing existing lambda resource ARNs that were exported as StackOutputs in the existing Lambda stack, but this is an implementation detail.
export class SqsExistingEventSourceStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);
const q = new sqs.Queue(this, 'MyQueue');
const lambdaFunction = lambda.Function.fromFunctionAttributes(this, `function`, {
functionArn: cdk.Fn.importValue('MinimalLambdaArn'),
role: iam.Role.fromRoleArn(this, 'importedRole', cdk.Fn.importValue('MinimalLambdaRoleArn')),
});
lambdaFunction.addEventSource(new sources.SqsEventSource(q, {batchSize: 10,}) );
}
}
The OP does not show how you are adding the PVInfraSQSTopic construct to a stack, which may also be a source of "scope" errors.
I have created an application with electron and next.from main window, creating child window. I want to load file to child window but it is throwing file not found error.
loading file is in: renderer/components/overlay/overlay.html
import {app,BrowserWindow,remote,globalShortcut} from 'electron';
import OverlayWindow from '../components/overlay/overlay';
const path = require('path');
const url = require('url');
const os=require('os');
export const createOverlayWindow=()=>{
const overlayWindow = new remote.BrowserWindow({
width:300,
height:100,
frame:false,
webPreferences: {
transparent: true,
nodeIntegration: true
}
});
// overlayWindow.setAlwaysOnTop(true);
// overlayWindow.loadURL(`file://${__dirname}/renderer/components/overlay/overlay.html`)
console.log(path.join(__dirname, '..', 'overlay.js'));
const urlFormat=url.format({
pathname: path.join(__dirname,"renderer/components/overlay/overlay.html" ),
protocol: "file:",
slashes: true
})
console.log(urlFormat);
overlayWindow.loadURL(urlFormat);
const shortcut = remote.globalShortcut.register('Alt+Space', () => {
console.log('shortcut registered');
overlayWindow.show();
});
overlayWindow.webContents.setFrameRate(30)
}