Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab complete #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Lab complete #1

wants to merge 1 commit into from

Conversation

IkenoXamos
Copy link
Owner

No description provided.

@@ -1,6 +1,6 @@
FROM public.ecr.aws/lambda/python:3.8
COPY requirements.txt ${LAMBDA_TASK_ROOT}
RUN pip3 install --no-cache-dir -r requirement.txt
RUN pip3 install --no-cache-dir -r requirements.txt
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a typo. Line 2 of the Dockerfile clearly shows requirements.txt as the file name. As such, the Dockerfile would have failed on line 3 with a "file not found" error.

@@ -7,4 +7,4 @@


def lambda_handler(event, context):
print("Hello World!")
print("Hello World! This has been changed!")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was introduced in order to demonstrate triggering the pipeline.

@@ -44,9 +44,16 @@ resource "aws_iam_role_policy" "iam_policy_for_lambda" {
}
POLICY
}

# Reference: https://github.com/hashicorp/terraform-provider-aws/issues/7385#issuecomment-756672006
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were introduced in order to solve the problem where the pipeline would succeed, but the lambda function would not use the updated code.

The way this works is by leveraging the source_code_hash attribute of the aws_lambda_function resource.
The docs regarding this can be found here.

In particular, we are following an example found here that explains why and how we need to manage the source code hash while working with images from ECR.

@@ -1,3 +1,13 @@
provider "aws" {
region = "us-east-1"
}

data "aws_ecr_authorization_token" "token" {}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces the docker provider, and configures it's access from what is locally available.
The pipeline is already calling aws ecr get-login-password, which connects to AWS in order to access ECR.

This configuration simply leverages that. This is the recommended process as you can find here.

bucket = "jenkins-state-1988"
key = "codepipeline-lambda"
region = "us-east-1"
bucket = "revature-terraform"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned elsewhere, the terraform state is being kept in an S3 bucket that I already had pre-configured. I simply needed to update the configuration to reference my bucket.

It is also important to note, that this configuration had to have changed. It defaulted to a jenkins-state-1988 S3 bucket, but I don't believe this is accessible to us. Therefore, we are required to use our own bucket.

@@ -11,5 +12,9 @@ terraform {
version = "~> 4.15.1"
#Will allow installation of 4.15.1 and 4.15.10 but not 4.16.0
}
docker = {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we leveraged the docker provider in order to implement the source_hash_code solution, we must include the provider in our terraform configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant