Spring Data Neo4j Creating Dynamic Labels at Node (Java Node Entity) level - spring-data-neo4j

Springboot Application
Spring Data Neo4j
Connecting to Aura DB
I have a Node Entity called Group. I want to add Dynamic Labels at Node Level
public class Group implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(UUIDStringGenerator.class)
private String id;

Spring Data Neo4j supports dynamic labels via the #DynamicLabels annotation.
public class Group implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(UUIDStringGenerator.class)
private String id;
#DynamicLabels
public Set<String> myDynamicLabels;
}
More about this can be found in the documentation.

Related

AWS CDK - Connect a Network Load Balancer and a Neptune Cluster Endpoint together

For the past two days I've been struggling with exposing a Neptune endpoint to the public using an NLB in a single stack. The architecture was inspired by this document.
For the life of me I haven't been able to figure out how to obtain the IP address of the Neptune endpoint to use as the target of NLB's listener. The main issue resides in the conversion of the Neptune hostname to an IP address as required by NLB's target group IPTarget and how CDK synthesizes stacks before deployment.
I explored the use of CustomResources to no avail due to my limited familiarity with the topic (day 5 of my aws journey), and was hoping someone could point me in the right direction.
Here's my stack (CDK app repo here):
import { Construct } from "constructs";
import { Stack } from "aws-cdk-lib";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as elbv2 from "aws-cdk-lib/aws-elasticloadbalancingv2";
import * as neptune from "#aws-cdk/aws-neptune-alpha";
import { Props } from "../../_config";
import createVPC from "../helpers/createVPC";
import createNeptuneCluster from "../helpers/createNeptuneCluster";
import createNLB from "../helpers/createNLB";
export class ABCGraphStack extends Stack {
public readonly vpc: ec2.Vpc;
public readonly subnets: {
public: ec2.ISubnet[];
private: ec2.ISubnet[];
isolated: ec2.ISubnet[];
};
public readonly neptuneCluster: neptune.DatabaseCluster;
public readonly neptuneReadEndpoint: neptune.Endpoint;
public readonly neptuneWriteEndpoint: neptune.Endpoint;
public readonly nlb: elbv2.NetworkLoadBalancer;
constructor(scope: Construct, id: string, props: Props) {
super(scope, id, props);
// Create VPC for use with Neptune
const { vpc, subnets } = createVPC(props, this);
this.vpc = vpc;
this.subnets = subnets;
// Create Neptune Cluster
this.neptuneCluster = createNeptuneCluster(
props,
this,
this.vpc,
this.subnets
);
// Update Neptune Security Group to allow-all-in
this.neptuneCluster.connections.allowDefaultPortFromAnyIpv4(
"Allow All Inbound to Neptune"
);
// Add an ordering dependency on VPC.
this.neptuneCluster.node.addDependency(this.vpc);
// Output the Neptune read/write addresses
this.neptuneReadEndpoint = this.neptuneCluster.clusterReadEndpoint;
this.neptuneWriteEndpoint = this.neptuneCluster.clusterEndpoint;
// HOW TO GET IP ADDRESS OF this.neptuneWriteEndpoint.hostname?
// Create Network Load Balancer
this.nlb = createNLB(props, this, this.vpc, "????????", 8182);
this.nlb.node.addDependency(this.neptuneCluster);
}
}

Upload file to s3 using api gateway and read query params inside lambda

I've found this example for uploading image to s3 bucket using API Gateway.
At the end it will be stored in the s3 bucket hitting the following endpoint
https://abc.execute-api.ap-southeast-1.amazonaws.com/v1/mybucket/myobject.jpeg
I have lambda function which accepts several parameters
public async Task<string> FunctionHandler(MyRequest request, ILambdaContext context)
{
...
}
public class MyRequest
{
public double Price { get; set; }
public string Name { get; set; }
public Guid Id { get; set; }
}
My question is:
Is it possible to expand file upload using api gateway to accept query params (MyRequest in this case) and to pass that params to lambda function. Idea is to trigger lambda function once the file is uploaded and to read passed params inside lambda function.
Another idea is to store all params as part of the filename, for example:
https://abc.execute-api.ap-southeast-1.amazonaws.com/v1/mybucket/price_20-name_boston-id_123-myobject.jpeg and to parse that filename from the lambda. In this case I would parse that in the lambda.
Or is there another option you would suggest?

How to set environment variables for complex configuration parameters in AWS lambda using asp.net core 3.1 serverless?

In my asp.net core 3.1 web API launchsettings.json I have a environment variable named "AdminstratorConfig:AdminstratorPassword": "myPasswordValue"
Now in my code I also have a class named AppSettings defined like this:
public class AppSettings
{
public AdminstratorConfiguration AdminstratorConfig { get; set; }
}
public class AdminstratorConfiguration
{
public string AdminstratorPassword { get; set; }
}
When running in my local I can bind the environment variable into my AppSettings instance using something like this in the Startup
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
var appSettings = new AppSettings();
Configuration.Bind(appSettings);
// Here appSettings.AdminstratorConfig.AdminstratorPassword contains value 'myPasswordValue'
}
}
I cal also load the same from my appsettings.json if I have my configuration defined as
{
"AdminstratorConfig":
{
"AdminstratorPassword": "myPasswordValue"
}
}
However after deploying my application as AWS serverless lambda I tried to set the same environment variable in Lambda configuration section but it doesn't allow special characters here ' : '
Is there a way we can set and load these complex environment variables in AWS Lambda similar to my local?
if not what are the possible alternate approaches?
You can use __ (double underscore) instead of : (colon), so the environment variable in lambda would be AdministratorConfig__AdministratorPassword as the key and your myPasswordValue as the value.
See the documentation.

AWS CDK Java - Template format error: Mappings element count 0 should be greater than 0

I would like to use AWS CDK with Java to create one simple VPC, with a public subnet, a security group and a EC2 instance. The Java class is the following, very simple:
public class CDKStack extends Stack {
public CDKStack(final Construct scope, final String id) {
this(scope, id, null);
}
public CDKStack(final Construct scope, final String id, final StackProps props) {
super(scope, id, props);
// Create public subnet
SubnetConfiguration publicSubnet = SubnetConfiguration.builder()
.name("public-subnet")
.subnetType(SubnetType.PUBLIC)
.cidrMask(24)
.build();
List<SubnetConfiguration> subnetList = new ArrayList<>();
subnetList.add(publicSubnet);
// Create VPC with subnet above
Vpc vpc = new Vpc(this, "vpc-from-ckd", VpcProps.builder()
.cidr("10.0.0.0/16")
.maxAzs(1)
.subnetConfiguration(subnetList)
.build());
// Create the Security Group inside the VPC
SecurityGroup securityGroup = new SecurityGroup(this, "sg-cdk-java", SecurityGroupProps.builder()
.vpc(vpc)
.allowAllOutbound(true)
.build());
// Create image and EC2 instance
final GenericLinuxImage genericLinuxImage = new GenericLinuxImage(Collections.emptyMap());
Instance.Builder.create(this, "EC2 from CDK")
.instanceType(new InstanceType("t2.micro"))
.machineImage(genericLinuxImage)
.securityGroup(securityGroup)
.vpc(vpc)
.build();
}
}
Though, when I run cdk deploy (on Windows 10) I get the following error that I do not understand:
CDKStack: deploying...
CDKStack: creating CloudFormation changeset...
❌ CDKStack failed: Error [ValidationError]: Template format error: Mappings element count 0 should be greater than 0
Any help that could clarify what I'm doing wrong would be really appreciated, as I am going through samples and API documentation, but I cannot figure it out.
After some more search, I paid more attention to the error message and realized that Mappings refers to the Cloudformation Mappings (sounds obvious now that I think about it, but from the error message it is absolutely not clear, it seems more a verb in a sentence) and from their example in the official doc I thought it could be related to the environment variables.
So, I set them explicitly in the Java class and now it works:
.env(Environment.builder()
.account("1234567890")
.region("aws-region-name")
.build())

AWS IAM CDK: tagging and creating access key for a user

I'm trying to use AWS CDK to create a user with minimal permissions through a custom policy, but I'm stuck with tagging that user and creating its access keys.
Below there's my code:
public class Sample extends App {
public static void main(final String[] args) {
App app = new App();
new UserStack(app, "user-stack");
app.run();
}
public static class UserStack extends Stack {
// Not able to add Tag and Create Access Key
public UserStack(final App parent, final String name) {
super(parent, name);
PolicyStatement statement = new PolicyStatement(PolicyStatementEffect.Allow);
statement.addResource("*");
statement.addAction("lambda:UpdateFunctionCode");
User user = new User(this, "LambdaDeployer", UserProps.builder().withUserName("lambda-deployer").withPath("/").build());
user.addToPolicy(statement);
Tag tag = new Tag("Project", "devops");
// how to tag the user ??
new CfnOutput(this, "LambdaDeployerOutputAccessKey", CfnOutputProps.builder().withValue("AWS::IAM::AccessKey").build());
new CfnOutput(this, "LambdaDeployerOutputSecretAccessKey", CfnOutputProps.builder().withValue("AWS::IAM::SecretAccessKey").build());
}
}
}
You'll probably have to use a Custom Resource in order to call the TagUser API, since adding tags to a User is not available natively in CloudFormation.
You can use a new feature in the CDK to help you author your Custom Resource: https://github.com/awslabs/aws-cdk/pull/1850