<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Signet Seal</title>
    <description>The latest articles on DEV Community by Signet Seal (@signet-seal).</description>
    <link>https://dev.to/signet-seal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F4848%2F184b92cb-7c61-4d14-a00f-bfb88e8c2e0a.jpg</url>
      <title>DEV Community: Signet Seal</title>
      <link>https://dev.to/signet-seal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/signet-seal"/>
    <language>en</language>
    <item>
      <title>Enable Lambda Insights Using Python AWS CDK</title>
      <dc:creator>chrishart0</dc:creator>
      <pubDate>Tue, 23 Nov 2021 03:17:17 +0000</pubDate>
      <link>https://dev.to/signet-seal/enable-lambda-insights-using-python-aws-cdk-23g3</link>
      <guid>https://dev.to/signet-seal/enable-lambda-insights-using-python-aws-cdk-23g3</guid>
      <description>&lt;h2&gt;
  
  
  Code for enabling Lambda Insights with the Python CDK
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Define the layer, make sure you use the right layer for your region and the pick the most up to date layer https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-extension-versions.html

layerArn='arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:14'
insight_layer = _lambda.LayerVersion.from_layer_version_arn(self,'lambda_insights_layer',layerArn)

#Add the layer to the function as shown below
_lambda.Function(
    self, 'my_function',
    runtime=_lambda.Runtime.PYTHON_3_8,
    handler='my_function.handler',
    code=_lambda.Code.from_asset(
        path = 'lambda'
    ),
    layers=[insight_layer]
)

# Optional: Add the managed policy 
If using the `AWSLambdaBasicExecutionRole`, which CDK uses by default when creating a Lambda function, there is no need to do this. Otherwise, add the `CloudWatchLambdaInsightsExecutionRolePolicy` managed policy to the function.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; make sure to pick the most up to date and correct region ARN for the Lambda Insights Extension layer. Reference &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-extension-versions.html"&gt;these docs here&lt;/a&gt; for ARNs for all regions and version&lt;/p&gt;

&lt;p&gt;Here are the &lt;a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-Getting-Started-clouddevelopmentkit.html"&gt;AWS docs&lt;/a&gt; on how to enable Lambda Insights for the Typescript CDK.&lt;/p&gt;

&lt;h2&gt;
  
  
  More CDK or AWS Serverless Questions?
&lt;/h2&gt;

&lt;p&gt;Feel free to leave a comment here or hit us up on &lt;a href="https://www.linkedin.com/company/signet-seal"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Want to learn more about how SignetSeal can help make your chats more secure? Read more about us on our website &lt;a href="https://signetseal.com/"&gt;SignetSeal.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>lambda</category>
      <category>monitoring</category>
      <category>devops</category>
    </item>
    <item>
      <title>Configure CORS for an S3 Bucket Using Python AWS CDK</title>
      <dc:creator>chrishart0</dc:creator>
      <pubDate>Tue, 23 Nov 2021 02:41:54 +0000</pubDate>
      <link>https://dev.to/signet-seal/configure-cors-for-an-s3-bucket-using-python-aws-cdk-4kn2</link>
      <guid>https://dev.to/signet-seal/configure-cors-for-an-s3-bucket-using-python-aws-cdk-4kn2</guid>
      <description>&lt;h2&gt;
  
  
  Get right to it, here is the code
&lt;/h2&gt;

&lt;p&gt;Python CDK code for configuring CORS on an S3 bucket.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bucket = s3.Bucket(self, "myBucket",
    cors=[
        s3.CorsRule(
            allowed_headers=[CORS_headers],
            allowed_methods=[s3.HttpMethods.PUT, s3.HttpMethods.POST, s3.HttpMethods.GET, s3.HttpMethods.DELETE],
            allowed_origins=[CORS_url]
        )
    ]
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A list of the HTTP methods which can be configured can be found here in the &lt;a href="https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3/HttpMethods.html#aws_cdk.aws_s3.HttpMethods"&gt;aws_cdk.aws_s3.HttpMethods docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Relevant docs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3/Bucket.html"&gt;https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3/Bucket.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html"&gt;https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  More CDK or AWS Serverless Questions?
&lt;/h2&gt;

&lt;p&gt;Feel free to leave a comment here or hit us up on &lt;a href="https://www.linkedin.com/company/signet-seal"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Want to learn more about how SignetSeal can help make your chats more secure? Read more about us on our website &lt;a href="https://signetseal.com/"&gt;SignetSeal.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloudnative</category>
      <category>cdk</category>
      <category>s3</category>
    </item>
    <item>
      <title>Create S3 Lifecycle Rules with Tag Filters Using Python AWS CDK</title>
      <dc:creator>chrishart0</dc:creator>
      <pubDate>Thu, 21 Oct 2021 23:55:21 +0000</pubDate>
      <link>https://dev.to/signet-seal/create-s3-lifecycle-rules-with-tag-filters-using-python-aws-cdk-4d2o</link>
      <guid>https://dev.to/signet-seal/create-s3-lifecycle-rules-with-tag-filters-using-python-aws-cdk-4d2o</guid>
      <description>&lt;h2&gt;
  
  
  Get right to it, here is the code
&lt;/h2&gt;

&lt;p&gt;Python CDK code for creating an S3 bucket with a lifecycle rule which uses a tag filter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bucket = s3.Bucket(self, "myBucket",
    lifecycle_rules = [
        s3.LifecycleRule(
            id="example-rule-made-with-python-cdk",
            expiration=core.Duration.days(1),
            tag_filters={ 
                'Key': 'delete_in_1_day', 
                'Value': 'true'
            }
        )
    ]
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Relevant CDK docs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3/Bucket.html"&gt;https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3/Bucket.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3/LifecycleRule.html#aws_cdk.aws_s3.LifecycleRule"&gt;https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3/LifecycleRule.html#aws_cdk.aws_s3.LifecycleRule&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; AWS Lifecycle rules do not get more precise than 24 hours[&lt;a href="https://aws.amazon.com/premiumsupport/knowledge-center/s3-lifecycle-rule-delay/"&gt;docs&lt;/a&gt;]. &lt;/p&gt;

&lt;h2&gt;
  
  
  More CDK or AWS Serverless Questions?
&lt;/h2&gt;

&lt;p&gt;Feel free to leave a comment here or hit us up on &lt;a href="https://www.linkedin.com/company/signet-seal"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Want to learn more about how SignetSeal can help make your chats more secure? Read more about us on our website &lt;a href="https://signetseal.com/"&gt;SignetSeal.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloudnative</category>
      <category>cdk</category>
      <category>s3</category>
    </item>
    <item>
      <title>Create CloudWatch Alarms with Python AWS CDK </title>
      <dc:creator>chrishart0</dc:creator>
      <pubDate>Thu, 21 Oct 2021 23:24:14 +0000</pubDate>
      <link>https://dev.to/signet-seal/create-cloudwatch-alarms-with-python-aws-cdk-1e53</link>
      <guid>https://dev.to/signet-seal/create-cloudwatch-alarms-with-python-aws-cdk-1e53</guid>
      <description>&lt;h2&gt;
  
  
  Create the alarm
&lt;/h2&gt;

&lt;p&gt;Put this into your Python AWS CDK stack to create an alarm on a bucket asigned to a varibale named &lt;code&gt;bucket&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bucket = s3.Bucket...

s3_size_alarm = cloudwatch.Alarm(self, 'bucket_overloaded_alarm',
    metric= cloudwatch.Metric(
        namespace = "AWS/S3", 
        metric_name = "BucketSizeBytes",
        dimensions={
            "BucketName": bucket.bucket_name,
            "StorageType": "StandardStorage",
        },
        period = core.Duration.days(1),
        statistic="Maximum",
    ), 
    evaluation_periods=1, 
    threshold=1000000000 #1 GB
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a CloudWatch alarm which:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Alarm if the size of the bucket goes over 1GB&lt;/li&gt;
&lt;li&gt;Only monitors objects with the &lt;code&gt;StandardStorage&lt;/code&gt; type&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Relevant CDK docs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cloudwatch/Alarm.html"&gt;https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cloudwatch/Alarm.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cloudwatch/Metric.html"&gt;https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_cloudwatch/Metric.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Don't rely on an alarm watching the &lt;code&gt;BucketSizeBytes&lt;/code&gt; metric to make sure your bucket doesn't grow too large. This metric is &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/cloudwatch-monitoring.html"&gt;only collected once a day&lt;/a&gt;. Consider opting in to &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/metrics-dimensions.html"&gt;S3 request metrics&lt;/a&gt; for more in-depth S3 monitoring&lt;/p&gt;

&lt;h2&gt;
  
  
  Create alarm action
&lt;/h2&gt;

&lt;p&gt;Alarms aren't very useful if they don't do anything. Setup some actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;topic = sns.Topic.from_topic_arn(self,'snstopic',"arn:aws:sns:us-east-1:123456789012:alarm-go-ahhhhhhhhhhhh")

s3_size_alarm.add_alarm_action(
    cloudwatch_actions.SnsAction(
        topic = topic
    )
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Relevant CDK docs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_sns/Topic.html#aws_cdk.aws_sns.Topic.from_topic_arn"&gt;https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_sns/Topic.html#aws_cdk.aws_sns.Topic.from_topic_arn&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  More CDK or AWS Serverless Questions?
&lt;/h2&gt;

&lt;p&gt;Feel free to leave a comment here or hit us up on &lt;a href="https://www.linkedin.com/company/signet-seal"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Want to learn more about how SignetSeal can help make your chats more secure? Read more about us on our &lt;a href="https://signetseal.com/"&gt;website&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cdk</category>
      <category>iac</category>
      <category>cloudnative</category>
    </item>
  </channel>
</rss>
