I created a lambda via ts file with the following specifications:
description: 'Lambda request handler to automate the DDL commands',
name: LAMBDA_NAME,
timeout: Duration.minutes(10),
memorySize: 512,
componentName: 'DdlLambda',
runtime: Runtime.JAVA_11,
handler: 'handler.ddllambda',
packageName: 'DDLManagementLambda-1.0',
deadLetterQueueEnabled: false,
tracing: Tracing.ACTIVE,
profiling: false,
logRetention: RetentionDays.FOUR_MONTHS
Created a custom resource with
import {CustomResource} from "monocdk";
const customResource = new CustomResource(this, 'CustomResource', {
serviceToken: ddllambda.functionArn,
properties: {
version: "version_0"
}
But I am getting the error
CloudFormation did not receive a response from your Custom Resource.
Please check your logs for requestId [c634da01-9c4d-4f8e-a2fc-a28724aa8206].
If you are using the Python cfn-response module, you may need to update your
Lambda function code so that CloudFormation can attach the updated version.
I am not able to find the logs for the given requestId. What am I missing here?
You should use cfn-response.send in your custom resource to notify CloudFormation.
Find logs in the console:
For the logs, you can access them from the console in the lambda page, click Monitor then View logs in CloudWatch:
Once in CloudWatch click Search all:
Then in the search box paste your Request ID in double quotes:
Find logs using aws-cli: See this answer
I was not sending the response back from lambda, hence was getting the error. Referring this code helped https://github.com/stelligent/cloudformation-custom-resources/blob/master/lambda/java/src/main/java/com/stelligent/customresource/CustomResourceHandler.java.
Related
I'm trying to set up email alerts for my Lambda errors. I can update my .yml file to create a new topic and this works OK:
custom:
alerts:
stages:
- production
- dev
- development
dashboards: true
topics:
alarm:
topic: ${self:service}-${sls:stage}-alerts-alarm
notifications:
- protocol: email
endpoint: myemail#domain.com
alarms:
- functionErrors
- functionThrottles
- functionInvocations
- functionDuration
I receive emails as expected.
But when I try to use an existing SNS Topic, by following the SLS docs, nothing seems to happen. I've:
Created a Topic in the SNS console
Updated the .yml as per the docs:
custom:
alerts:
stages:
- production
- dev
- development
topics:
alarm:
topic: arn:aws:sns:${aws:region}:${aws:accountId}:myp-${sls:stage}-alerts
alarms:
- functionErrors
- functionThrottles
- functionInvocations
- functionDuration
The deploy works fine, but I don't get any emails when I trigger errors. What do I need to do?
I got it working, though I don't really know what I'm doing differently.
Successful methodology:
Create a Topic in the SNS console. Click 'Create Topic' after entering the following:
When taken to your new Topic summary screen, click the orange 'Create Subscription' Button. Select 'Email' from the Protocol dropdown. Enter your email address. Click the orange 'Create Subscription' button below:
Deploy Lambda with the command: sls deploy --stage dev and the following code in serverless.yml:
plugins:
- serverless-plugin-aws-alerts
# ... your function code, etc
custom:
alerts:
topics:
alarm:
topic: arn:aws:sns:${aws:region}:${aws:accountId}:myp-${sls:stage}-alerts
alarms:
- functionErrors
- functionThrottles
- functionInvocations
- functionDuration
nameTemplate: $[functionName]-$[metricName]-Alarm
prefixTemplate: $[stackName]
That should get it working. You can trouble shoot by going over to your Cloudwatch Console. Click All Alarms:
You should be able to see that your alarms have been created here, like this:
The names follow the instruction in the above serverless.yml file: nameTemplate: $[functionName]-$[metricName]-Alarm
Click the alarm name and in the top right of the next screen click Actions>Edit:
You can see that the FunctionName refers to your Lambda function:
Scroll down and click the 'Next' button. You can see at the bottom of the Notifications section of the next screen which Topic the Alert is sending to:
It says 'myp-dev-alerts'. So we know that this matches the Topic I created.
I want to use SSO in Outlook to get the BookstrapToken with MSGrapAccess and I'm getting the error "13012". In the documentation says that this error is only possible while sideloading, but I also get it once I deploy the addin.
I'm not doing anything special:
bootstrapToken = await OfficeRuntime.auth.getAccessToken({ allowSignInPrompt: true, allowConsentPrompt: true, forMSGraphAccess: true });
This is the error I get:
{code: 13012, message: "API is not supported in this platform.", name: "API Not Supported"}
All the permissions are granted in Azure.
Is it possible to get the BootstrapToken foMSGraphAccess or I need to use a different sign in method?
Thank you
I found the way to make it work with the parameter. The problem was that I was using allowConsentPrompt and forMSGraphAccess at the same time. Without allowConsentPrompt, I can use forMSGraphAccess with no problem.
I'm using aws-flow to interact with Amazon's Simple Workflow Server and I want to get logging set up to go to an external source (PaperTrail).
I've set my $logger to use PaperTrail and I pass this into the client I use to start the execution;
client = Aws::SWF::Client.new(region: 'eu-west-1', logger: $logger)
client.start_workflow_execution({
domain: domain,
workflow_id: ...,
workflow_type: {
name: "...",
version: ...
},
task_list: {
name: "..."
}
})
This successfully logs that the client has started, but no action from inside a Workflow or Activity gets logged.
From reading the documentation and this SO answer it seems like you need to specify a logger when creating new Activities, but I can't see how to do that.
The main workflow uses activity_client to select the Activitiy it needs, and the activity being called looks like;
class MyActivity
extend AWS::Flow::Activities
activity :my_activity do {
default_task_list: '...',
version: ...,
default_task_schedule_to_start_timeout: 60,
default_task_start_to_close_timeout: 60,
exponential_retry: { maximum_attempts: 2 }
}
I can't see anywhere with this setup that you can add a logger to.
Any help would be greatly appreciated
So it turns out aws-flow doesn't support logging.
There is some chat about it in issues and there is a PR which appears to fix things.
For my needs I just forked the project (which at the time of writing hasn't been updated in 2 years) and made the relevant changes for me.
I have an an AWS Lambda function that needs to connect to a remote TCP service. Is there any way to configure the Lambda function with the IP address of the remote service after the Lambda function has been deployed to AWS? Or do I have to bake the configuration into the packaged Lambda function before it's deployed?
I found a way that I use for supporting a test environment and a production environment that will help you.
For the test version of the function, I am calling it TEST-ConnectToRemoteTcpService and for the production version of the function I am naming the function PRODUCTION-ConnectToRemoteTcpService. This allows me pull out the environment name using a regular expression.
Then I am storing config/test.json and config/production.json in the zip file that I upload as code for the function. This zip file will be extracted into the directory process.env.LAMBDA_TASK_ROOT when the function runs. So I can load that file and get the config I need.
Some people don't like storing the config in the code zip file, which is fine - you can just load a file from S3 or use whatever strategy you like.
Code for reading the file from the zip:
const readConfiguration = () => {
return new Promise((resolve, reject) => {
let environment = /^(.*?)-.*/.exec(process.env.AWS_LAMBDA_FUNCTION_NAME)[1].toLowerCase();
console.log(`environment is ${environment}`);
fs.readFile(`${process.env.LAMBDA_TASK_ROOT}/config/${environment}.json`, 'utf8', function (err,data) {
if (err) {
reject(err);
} else {
var config = JSON.parse(data);
console.log(`configuration is ${data}`);
resolve(config);
}
});
});
};
Support for environment variables was added for AWS Lambda starting November 18, 2016. Adding a variable to an existing function can be done via command line as shown below or from the AWS Console.
aws lambda update-function-configuration \
--function-name MyFunction \
--environment Variables={REMOTE_SERVICE_IP=100.100.100.100}
Documentation can be found here.
You can invoke the Lambda function via SNS topic subscription and have it configure itself from the payload inside the SNS event.
Here's the official guide on how to do that Invoking Lambda via SNS.
A few options, depending on the use-case
If your config will not change then you can use S3 objects and access from Lambda or set your Lambda to trigger on new config changes. (Though this is the cheapest way, you are limited in what you can do compared to other alternatives)
If the config is changing constantly, then DynamoDB - Key/value is an alternative.
If DynamoDB is expensive for the frequent read/writes and not worth the value then you can have TCP service post config into a SQS queue. (or an SNS if you want to trigger when the service posts a new config)
I'am trying to get youtube video's comments from my dart console application. I create application in google console.
Then I try to get video list:
import "package:googleapis/youtube/v3.dart" as youtube;
import "package:http/http.dart" as http;
void main() {
http.Client client = new http.Client();
youtube.YoutubeApi api = new youtube.YoutubeApi(client);
api.videos.list("title", id: "ZkGSR0Q492g").then((youtube.VideoListResponse list) {
// print("List length: " + list.items.length);
});
}
When I run this file in console - I get error:
Uncaught Error: DetailedApiRequestError(status: 403, message: Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.)
I understand that I never indicated API-key applications. I think that the error due to this.
But I can not figure out where I need to specify it?
I guess you need to create an authenticated client using https://pub.dartlang.org/packages/google_oauth2_client (detailed instructions in the README.md)
Now I use package "googleapis_oauth". And in this package we have method clientViaApiKey in auth_io.dart. This is solve my problem.