Prevent new ARN Version generation on lambda layer update - aws-lambda

I have created a layer which contains some codes that can be used by multiple lambda function.
Something like this:
module.exports = {
"INVALID_RFC": {"code": "111", "message": "RFC Code is invalid"}
}
The problem is that whenever I make some update on the layer, AWS genertate a new version for it. Due to this, I have to manually update the version in all of the lambda. I understand its importance and use-case, but I want to prevent it. Manullay updating the Lambda everytime is too much time taking.

Related

Deploy lambda layer and lambda function at the same time to maintain them synchronized

I have...
Lambda layer that will be used across many other services (common-layer)
Lambda functions for users/orders/payments/etc
services/layers/common-layer
services/[users,orders/payments/etc]/**
In order to deploy stuff we need to go to the common-layer, hit serverless deploy, and then go to the other services and hit serverless deploy as well. If we continue doing this, we cannot achieve synchronized data.
Within the common-layer I have a super important function that needs to be always synchronized with other lambda functions.
// services/layers/common-layer
function getSuperDuperHyperImportantNumber() {
return 1;
}
// services/[users/orders/payments]
import { getSuperDuperHyperImportantNumber } from 'common-layer'
Later, specifications changed... Now we need rename the function to getCoolNumber and return 2 instead of 1
// services/layers/common-layer
function getCoolNumber() {
return 2;
}
// services/[users/orders/payments]
import { getCoolNumber } from 'common-layer'
So, how can I deploy these changes simultaneously to maintain lambdas services and the common-layer synchronized?
Will serverless-compose help?
Notes:
Within the lambda services I'm using a serverless plugin to always point at the latest version of mentioned common-layer
This problem seems the same as the migrations stuff within databases-code
You could add the lambda layer to your serverless deployment. When you run 'sls deploy', it should deploy the layer, then deploy the lambda function with the latest Lambda Layer version attached. Here's a reference template that works this way. The Lambda Layer is specified at the 'provider' level which will apply to all lambda functions in the same file.
https://carova.io/snippets/serverless-aws-add-lambda-layer-to-lambda-function

How to create an EventBridge (CloudWatch Events) rule and add it to a Lambda function as a trigger using CDK?

I'm trying to create an EventBridge (CloudWatch Events) Rule and have that rule added as a trigger to an existing Lambda function.
const notificationFunction = lambda.Function.fromFunctionArn(this,
'DevopsNotificationLambda',
_props.notificationLambdaArn
);
const rule = new Rule(this, `${stackPrefix}-EventRule`, {
eventPattern: {
source: ['aws.codepipeline'],
detailType: ['CodePipeline Pipeline Execution State Change'],
detail: {pipeline: [pipeline.pipelineName]}
},
});
notificationFunction.addPermission(`${stackPrefix}-CloudWatchPermission`, {
principal: new ServicePrincipal('events.amazonaws.com'),
sourceArn: rule.ruleArn
});
rule.addTarget(new LambdaFunction(notificationFunction));
The code creates the EventBridge with the Lambda target correctly, but it doesn't add the trigger to the actual Lambda. I have to manually add the EventBridge to the Lambda through the AWS Web Console.
Seems like it's not enough to add the Lambda as a target to the Event Rule. How should I add the Event Rule as a trigger to the Lambda?
From Importing existing external resources in the CDK Developer Guide.
Although you can use an imported resource anywhere, you cannot modify the imported resource. For example, calling addToResourcePolicy (Python: add_to_resource_policy) on an imported s3.Bucket does nothing.
You cannot add a trigger to notificationFunction from the CDK stack because notificationFunction is an external resource.

Nesting custom resources in chef

I am trying to build a custom resource which would in turn use another of my custom resource as part of its action. The pseudo-code would look something like this
customResource A
property component_id String
action: doSomething do
component_id = 1 if component_id.nil?
node.default[component_details][component_id] = ''
customResource_b "Get me component details" do
comp_id component_id
action :get_component_details
end
Chef::log.info("See the output computed by my customResourceB")
Chef::log.info(node[component_details][component_id])
end
Thing to note:
1. The role of customResource_b is to make a PS call to a REST web service and store the JSON result in node[component_details][component_id] overriding its value. I am creating this attribute node on this resource since I know it will be used later one, hence avoiding compile time issues.
Issues I am facing:
1. When testing a simple recipe that calls this resource in chef-client, the code in the resource gets executed to the last log line and after that the call to customResource_b is made. Which is something I am not expecting to happen.
Any advice would be appreciated. I am also quite new to Chef so any design improvements are also welcome
there is no need to nest chef resources, rather use chef idompotance, guards and notification.
and as usualy, you can always use a condition to decide which cookbook\recipe to run.

How to create Apis on Spring, that are using up to date environment values

I want to create API, which takes part of its input from environment (urls etc..). Basically a Jar file.
I also wan't the values being auto updated when application.properties changes. When there is change, this is called:
org.springframework.cloud.endpoint.RefreshEndpoint#refresh
However, I consider it bad practice to have magic env variable keys like 'server.x.url' in the Api contract between client application and the jar. (Problem A)
That's why I'd like to use Api like this. But there's problem of old values.
public class MyC {
TheAPI theApi=null;
void MyC(){
theApi = new TheApi();
theApi.setUrl( env.get("server.x.url") );
}
doStuff() {
theApi.doStuff(); // fails as theApi has obsolete value of server.x.url, Problem B
}
So either I have ugly API contract or I get obsolete values in the API calls.
I'm sure there must be Spring way of solving this, but I cant get it to my head just now.

Meteor 0.5.9: replacement for using Session in a server method?

So, I was attempting to do something like the following:
if(Meteor.isServer){
Meteor.methods({connect_to_api: function(vars){
// get data from remote API
return data;
}});
}
if(Meteor.isClient){
Template.myTpl.content = function(){
Meteor.call('connect_to_api', vars, function(err,data){
Session.set('placeholder', data);
});
return Session.get('placeholder');
};
}
This seemed to be working fine, but, of course, now breaks in 0.5.9 as the Session object has been removed from the server. How in the world do you now create a reactive Template that uses a server-only (stuff we don't want loading on the client) method call and get data back from that Method call. You can't put any Session references in the callback function because it doesn't exist on the server, and I don't know of any other reactive data sources available for this scenario.
I'm pretty new to Meteor, so I'm really trying to pin down best-practices stuff that has the best chance of being future-proof. Apparently the above implementation was not it.
EDIT: To clarify, this is not a problem of when I'm returning from the Template function. This is a problem of Session existing on the server. The above code will generate the following error message on the server:
Exception while invoking method 'connect_to_api' ReferenceError: Session is not defined
at Meteor.methods.connect_to_api (path/to/file.js:#:#)
at _.extend.protocol_handlers.method.exception ... etc etc
Setting the session in the callback seems to work fine, see this project I created on github: https://github.com/jtblin/meteor_session_test. In this example, I return data in a server method, and set it in the session in the callback.
There are 2 issues with your code:
1) Missing closing brace placement in Meteor.methods. The code should be:
Meteor.methods({
connect_to_api: function(vars) {
// get data from remote API
return data;
}
});
2) As explained above, you return the value in the session, before the callback is completed, i.e. before the callback method had the time to set the session variable. I guess this is why you don't see any data in the session variable yet.
I feel like an idiot (not the first time, not the last). Thanks to jtblin for showing me that Session.set does indeed work in the callback, I went back and scoured my Meteor.method function. Turns out there was one spot buried in the code where I was using Session.get which was what was throwing the error. Once I passed that value in from the client rather than trying to get it in the method itself, all was right with the world.
Oh, and you can indeed order things as above without issue.

Resources